DOM Functions Reference

Table of contents


Introduction

The DOM functions manipulate DOM elements. All DOM functions are properties of the global/window object and may be used without importing.


DOM Functions

addCssClass()

Syntax

addCssClass(arg1, ...classNames)

Adds CSS classes to an element, object, or string. The arguments in classNames are strings of class names separated by spaces.

If arg1 is a string, it is considered to be class names separated by spaces, and the class names in the classNames arguments are added to arg1 if they don't exist. The resulting string of class names is returned.

If arg1 is an object or DOM element, then the class names in the classNames arguments are added to the class names in arg1.className if they don't exist. If arg1.className does not exist, then arg1.className is set to the class names in the classNames arguments with any duplicates removed.

Parameters

Return value

If arg1 is a string, then a string is returned containing all the CSS classes specified in the arguments without duplicates. If arg1 is a DOM element or object, then undefined is returned.


chooseCssClass()

Syntax

chooseCssClass(arg1, choice, ...choices)

Adds a single choice of CSS class name to the string, object, or DOM element specified by arg1. All the remaining choices are removed. The choice argument is an index into the choices arguments. This is useful when a CSS class string must have one of several different class names but not more than one.

Parameters

Return value

If arg1 is a string, then a string is returned containing all the CSS classes with the chosen class names, with the others removed. If arg1 is a DOM element or object, then undefined is returned.


eltGetAncestorByTag()

Syntax

eltGetAncestorByTag(elt, tag)

Return the enclosing element with the given tag. For example, eltGetAncestorByTag(elt, 'tr') returns the enclosing table row.

Parameters

Return value

A DOM element, if the tag is found, or null otherwise.


eltOuterHeight()

Syntax

eltOuterHeight(elt)

Returns the height of the element's bounding box in pixels (px units).

Parameters

Return value

A number.


eltOuterWidth()

Syntax

eltOuterWidth(elt)

Returns the width of the element's bounding box in pixels (px units).

Parameters

Return value

A number.


eltTransition()

Syntax

Returns a Promise that resolves when the transition is complete.elt, startFn)

Asynchronously set up a transition on a DOM element.

startFn is a function that is called asynchronously when the current thread completes. This allows eltTransition() to be called before the element is fully painted with it's current style. At that point, the startFn can set up a transition or a new CSS class with a transition. The startFn is passed the DOM element as its single argument.

eltTransition() returns a Promise that resolves when the transition is complete.

Parameters

Return value

A Promise that resolves when the transition is complete.


evtGetPointerX()

Syntax

evtGetPointerX(evt)

Returns the client X offset in pixels from the evt event object. On touch devices it returns the first touch point's X offset.

Parameters

Return value

A number.


evtGetPointerY()

Syntax

evtGetPointerY(evt)

Returns the client Y offset in pixels from the evt event object. On touch devices it returns the first touch point's Y offset.

Parameters

Return value

A number.


getElt()

Syntax

getElt(id)

Returns the DOM element whose ID string is id. getElt() generates an assertion failure if the ID is not found.

Parameters

Return value

A DOM element.


hasCssClass()

Syntax

hasCssClass(arg1, className)

Return true if the DOM element, object, or string contains the string className.

If arg1 is a string, it is considered to be class names separated by spaces, and hasCssClass() returns true if the string includes className. It returns false if className is not present.

If arg1 is an object or DOM element, then hasCssClass() returns true if arg1.className includes className. It returns false if className is not present or arg1.className does not exist.

Parameters

Return value

A Boolean


hasElt()

Syntax

hasElt(id)

Returns true if the DOM element whose ID string is id exists.

Parameters

Return value

A Boolean.


isDomNode()

Syntax

isDomNode(arg)

Returns true if arg is a DOM element.

Parameters

Return value

A Boolean.


replaceCssClass()

Syntax

replaceCssClass(arg1, oldClass)
replaceCssClass(arg1, oldClass, newClass)

Deletes the CSS classes in oldClass and adds the CSS classes in newClass to the element, object, or string specified by arg1. If newClass is not provided, then the oldClass classes are deleted.

If arg1 is a string, it is considered to be class names separated by spaces, and the class names in oldClass are deleted, and the class names in the newClass are added if they don't exist. The resulting string of class names is returned.

If arg1 is an object or DOM element, then the class names in oldClass are deleted from arg1.className, and the class names in the newClass are added to arg1.className, if they don't exist. If arg1.className does not exist, then arg1.className is set to the class names in the newClass argument with any duplicates removed.

Parameters

Return value

If arg1 is a string, then a string is returned containing the result of deleting and adding the specified classes to the original string without duplicates. If arg1 is a DOM element or object, then undefined is returned.