1. add-class

add-class(class, before-class?, element?)

Add CSS class class to the list of “interned” CSS classes of element element. Does nothing at all if element element already has this CSS class.

For this command to work, command parse-styles must have been invoked in order to “intern” the CSS classes found in all the elements of the document being edited.

class

The CSS class name to be added.

before-class

Specifies before which class in the list of interned CSS classes of element element, class should be inserted. Defaults to "", which means: at the end of the list.

  • before-class may be the empty string "", which means add class at the end of the list.

  • before-class may be a class name. CSS class class is inserted in the list before class name before-class if found, at the end of the list otherwise.

  • before-class may be a class pattern. CSS class class is inserted in the list before the first class name matching pattern before-class if found, at the end of the list otherwise.

    A class pattern has the following syntax: /pattern/ or ^pattern$ (which is equivalent to /^pattern$/), where pattern is a regular expression pattern.

element

The element to which class should be added. Defaults to the context node, if the context node is an element.

Examples:

(: Append "role-xref" to the list of classes of context element. :)
add-class("role-xref");

(: Insert "role-xref" before "c-Hyperlink"
   in the list of classes of context element. :)
add-class("role-xref", "c-Hyperlink");

(: Insert "role-xref" before first class matching "^c-.+$" 
   in the list of classes of context element. :)
add-class("role-xref", "^c-.+$");

(: Append "role-figcaption" to the list of classes of $captionPara. :)
add-class("role-figcaption", "", $captionPara);

See also remove-class.

Related XPath extension functions: get-class.