0

JS classlist vs classname

I don't get the difference between using classname vs classlist??? Both can display all the class(s) within an element. But classlist allows you to target individual class within the element. It just seems like classlist is a much better option compared to classname...?? And like changing an element via classname will change ALL the classes inside an element??

23rd Apr 2019, 11:32 AM
J3fro C
J3fro C - avatar
1 Resposta
+ 2
className and classList. InJavaScript, there are two main ways to add and remove classes dynamically to a DOM element. The one is via the property className which returns a string and the other via the propertyclassList, which returns a DOMTokenList object with some useful methods.
23rd Apr 2019, 11:34 AM
Alessio Benvenuti
Alessio Benvenuti - avatar