addClass()
Adds the specified class(es) to one ore more HTML elements, which can be:
- The elements that match the selector of a script (see results).
- One element that matches the selector of a script that runs for "Each matched element" (see this and Setting the scope of a script).
- The elements returned by a query in the template (see query()).
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.
Copy
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.
Copy
results.addClass("foo bar");
Selector | Matched element | Matched element after script execution |
---|---|---|
p | <p>Hello world</p> | <p class="foo bar">Hello world</p> |