Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: ca5f9f3f63
Fetching contributors…

Cannot retrieve contributors at this time

92 lines (60 sloc) 2.278 kb

dojo.replaceClass

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

Introduction

Replaces one or more classes on a node if not present. Operates more quickly than calling dojo.removeClass and dojo.addClass.

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

Usage

The function takes up to three arguments:

  1. A DOM node or its node id (as a string).
  2. A String class name to add, or several space-separated class names, or an array of class names.
  3. A String class name to remove, or several space-separated class names, or an array of class names.

Dojo 1.7+ (AMD)

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

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

Dojo < 1.7

Examples

Replace all classes

The following example replace all classes with addMe :

Available in dojo.NodeList() for multiple toggles

See also

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