DOM: List/Add/Remove Class Attribute

By Xah Lee. Date: . Last updated: .

This page shows you how to list/add/remove a HTML/XML element's class attribute.

Use the following methods to change a class value of a element.


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






Browser Support

classList is supported by Internet Explorer 10 (), and earlier by other browsers.

Basic DOM Methods Topic

  1. DOM: Basic DOM Methods
  2. DOM: Get Elements by ID, Tag, Name, Class, CSS Selector
  3. DOM: Get Element's Attribute Value
  4. DOM: Set Element's Attribute Value
  5. DOM: List/Add/Remove Class Attribute
  6. DOM: Node Type, Node Name, Node Value
  7. DOM: Navigate DOM Tree
  8. DOM: Add / Remove Event Handler
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Ask me question on patreon