Beey
Posted on Dec 6
Edited on Dec 6
Table Of Contents
What is ClassList and why it is useful
Working out what you can do with classList
Common Mistakes
What is ClassList and why it is useful
As introduced in part 4, you may know that you can edit an object's CSS with javascript:
const object = document . getElementById ( "object" ) ;
object . style = "color: red;" ;
Enter fullscreen mode
Exit fullscreen mode
The example is one method.
Another way which is considered better to use in some cases is by using classList .
Classlist can append, remove, and use conditional class removing instead of editing the style.
Example:
const element = document . getElementById ( "MyElement" ) ;
element . classList .…