DOM: List/Add/Remove Class Attribute

By Xah Lee. Date: . Last updated: .

Here's methods to list/add/remove a HTML/XML element's class attribute.

Example:

<div id="x48389" class="aaa bbb ccc"></div>
const xx = document. getElementById("x48389");

xx.classList;

xx.classList.add("hh");

xx.classList.remove("bbb");

xx.classList.contains("aaa");

xx.classList.toggle("aaa");

DOM How-To


Web Scripting Overview


HTML Input


Web Scripting Examples


Web Scripting Misc


jQuery


node.js

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials