4

I noticed that Datatables sometimes generates inline CSS (style='....'). Is there are way to remove them? Or at least make the code not add styles inline?

2 Answers 2

3

There are a few options in DataTables to turn off the element.style that generates with a table's generation. I've found that setting bAutoWidth : false can sometimes turn off all of the inline styles, (even though it's just meant to turn off the inline width option), as well as initializing the table outside of $(document).ready(function().

As for a single option to turn off all styles created by DataTables - I'm not sure there's a way to do that, but if someone else finds this old thread, try these two options and see if it fixes your problem!

Sign up to request clarification or add additional context in comments.

1 Comment

I tested it , and really works ..Now in chrome element.style {} is empty
1

The most accurate answer would be: yes, the code can be changed to stop adding style=... to the html BUT removing all of them would almost certainly break the datatable layout and its behavior.

Datatable plugin uses style="..." to set dynamic properties (like width, position) that (in most cases) cannot be determined before actually running the plugin. If they cannot be determined they cannot be styled beforehand using css classes so we end up in using style="..." for those.

1 Comment

I see. I read the documentation and I think that I can prevent those styles by setting some Settings on or off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.