JS: 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>
var xx = document.getElementById("x48389");






Browser Support

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

Basic DOM Methods Topic

  1. JS: Basic DOM Methods
  2. JS: Get Elements by ID, Tag, Name, Class, CSS Selector
  3. JS: Get Element's Attribute Value
  4. JS: Set Element's Attribute Value
  5. JS: List/Add/Remove Class Attribute
  6. JS: Node Type, Node Name, Node Value
  7. JS: Navigate DOM Tree
  8. JS: Add / Remove Event Handler
Like what you read? Buy JavaScript in Depth