Menu

The Classlist(CSS basics part 5/60)
📰

The Classlist(CSS basics part 5/60)

DEV Community: css·Beey·about 6 hours ago
#HUXHh9u3
#devtocss#devto#dev#classlist#element
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.