0

Some people state that changing the CSS via the style object is a bad practice.

For example doing something like this:

document.getElementById('message').style.fontWeight = 'bold';

Instead one should add / remove classes for influencing the layout.

Unfortunately nobody becomes precise why it is bad to use the style-object.

Therefore my question here:

Can someone explain why one shall avoid this technique?

bo256
  • 143
  • 6
  • It is personal opinion and using classes is normally better since you know where the styles are at. Sometimes you will see someone setting 10 style properties in a row and that is just a bad idea. – epascarello Jan 20 '16 at 13:57
  • With the above, you are going to add inline styles. And why inline styles are bad, here is a good reasoning - http://stackoverflow.com/questions/2612483/whats-so-bad-about-in-line-css – Nikhil Aggarwal Jan 20 '16 at 13:58
  • because it mixes program logic with presentation – Alnitak Jan 20 '16 at 14:02

0 Answers0