DEV Community

Olsha100
Olsha100

Posted on

Javascript - inline styling or manipulating CSS class list

Hi All,

In my journey of learning WebDev I constantly encounter a problem of changing style of an element using Javascript. There's one thing I can't figure out:

Is it better to change element's style with JS using "inline method" like:

button.style.color = 'white';

or trying to manipulate it e.g. by adding a class which contains such property to the element like:

button.classList.add('className')

At first glance I'd choose the "inline method" since it's easier and more flexible but I found out that adding inline CSS which in fact is done by this method is considered as a bad practice and can affect SEO.

What do you think about it? I'd really appreciate for an opinion of more experienced than me in this matter :)

Top comments (0)