dojo DOM Manipulation dom-class


Example

This module provides function that allows you to manipulate CSS classes of DOM elements.

Initialization

To be able to use the dom-class module we need to load it as fallow :

require(["dojo/dom-class"], function(domClass){
    // Write code here
});

contains()

This function checks if a node contains a specific class

Usage

 if (domClass.contains("someId", "className")){
     // do something if it contains 
 } 

add()

This function allows you to add CSS Classes to a DOM node without duplication.

Usage

domClass.add("someId", "className"); 

remove()

This function allows you to remove CSS Classes from a DOM node.

Usage

 domClass.remove("someId", "className");

replace()

This function allows you to remove classes and replace it with other classes.

Usage

 domClass.replace("someId", "addedClassName", "removedClassName");

toggle()

This function allows you to remove a class if it exist, or add it if it doesn't exist.

Usage

 domClass.toggle("someId", "className");