Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ca5f9f3f63
Fetching contributors…

Cannot retrieve contributors at this time

297 lines (190 sloc) 7.593 kb

dojo.removeClass

Project owner: Eugene Lazutkin
since: V0.9

Removes a class or a list of classes from a DOM node.

Introduction

Follows the same pattern as most Dojo functionality by accepting a string ID of a Node, or a DOM Node reference, removing a passed class from the class="" attribute.

Since Dojo 1.7, dojo.removeClass is exposed via the remove method of the dojo/dom-class module. An alias is kept in dojo/_base/html for backward-compatibility.

Usage

The function takes up to two arguments:

  1. A DOM node or its node id (as a string).
  2. Optional. A string, which can list classes separated by spaces, or an array of CSS classes as strings. In the latter case array elements cannot contain spaces.

If the second argument is not specified or undefined, all classes will be removed.

Space-separated classes, arrays, and optional removing of all classes are supported since 1.4.

Dojo 1.7+ (AMD)

When using AMD format in a fully baseless application, remove is accessed from the dojo/dom-class module.

Alternatively, you can load dojo base in AMD style and continue using dojo.removeClass in the define or require callback:

Dojo < 1.7

Examples

Remove a class

The following example removes the class "style1" from the node "example1":

See it in action:

Remove several classes as a string

The following example removes two classes: "style1" and "style2" from the node "example1":

See it in action:

Remove several classes as an array

The following example removes two classes: "style1" and "style2" from the node "example1":

See it in action:

Remove all classes

The following example removes all classes from the node "example1":

See it in action:

Remove from multiple nodes

removeClass is also available for :ref:`NodeLists <dojo/NodeList>`, so that it's also possible to remove classes for multiple nodes. The following example removes the class for each node in the NodeList returned from dojo.query:

See it in action:

See also

Jump to Line
Something went wrong with that request. Please try again.