addClass()

Adds the specified class(es) to one ore more HTML elements, which can be:

Adding a class has no effect if the class is already present.

addClass(classname)

Adds the specified class(es) to one or more HTML elements. This has no effect if the class is already present.

classname

String, space separated list of class names.

Examples

This script adds a class name to a paragraph.

results.addClass("foo");
Selector Matched element Matched element after script execution
p ​<p>Hello world</p> <p class="foo bar">Hello world</p>​


The following script adds two class names to a paragraph.

results.addClass("foo bar");
Selector Matched element Matched element after script execution
p ​<p>Hello world</p> <p class="foo bar">Hello world</p>​