Constructor
new module:br/util/ElementUtility()
Methods
-
(static) addAndRemoveClassNames(element, classesToAdd, classesToRemove)
-
Adds and/or removes the specified class names from the specified element. This operation is performed in a single DOM action, making this more efficient than adding/removing the classes individually. If a class exists in both the add and remove lists, the class will be added to the element.
Parameters:
Name Type Description elementElement The HTML DOM element to make the class changes to. classesToAddArray.<String> The list of class names that will be added to the list of existing classes. classesToRemoveArray.<String> The list of class names that will be removed from the list of existing classes. -
(static) addClassName(element, className)
-
Adds the specified class name to the list of CSS classes on the given element, if the class does not already exist.
Parameters:
Name Type Description elementElement The HTML DOM element to add the CSS class to. classNameString The class name that will be added to the list of existing classes. -
(static) discardChild(firstElement)
-
Discards one or more elements (all arguments passed will be discarded) by removing children, and removing it from any parentNode.
Parameters:
Name Type Description firstElementElement First Element DOM Element -
(static) getAncestorElementWithClass(element, className) → {DOMElement}
-
Returns the first element that contains the given class as part of its
classNamestring.Parameters:
Name Type Description elementElement the element to start the search at. classNameString the class name to look for. Returns:
The ancestor element with the specified class, or null.- Type
- DOMElement
-
(static) getElementsByClassName(domElement, tagName, className) → {Array.<DOMElement>}
-
Returns an array of DOM elements that match the specified tag name and class name.
Parameters:
Name Type Description domElementDOMElement The DOM element that should be used as the root of the search. tagNameString The tag name (can be *) of elements to search for. classNameString The CSS class name of the elements to search for. Returns:
An array of elements that match the specified criteria.- Type
- Array.<DOMElement>
-
(static) getNodeIndex(element)
-
Returns the node index of the element as it exists in the parent.
Parameters:
Name Type Description elementElement The element to get the index for. Throws:
Error If the specified element does not have a parent.Returns:
the node index -
(static) getPosition(elem)
-
Returns the absolute position of the element relative to the window in pixels. The position also takes into account any scrolling of parents.
Parameters:
Name Type Description elemDOMElement The DOM element to calculate the position of Returns:
\{left:x,top:y\} -
(static) getScrollOffset(elem) → {Object}
-
Returns the scrolled offset of the element (if any) in an object containing a left and top properties.
Parameters:
Name Type Description elemElement The DOM element to calculate the scrolled offset of. Returns:
\{left:x,top:y\}- Type
- Object
-
(static) getSize(elem)
-
Returns the bounding rectangle of the specified element.
Parameters:
Name Type Description elemObject The element to get the bounding rectangle for. Returns:
\{left:x,right:y\} -
(static) hasClassName(element, className) → {boolean}
-
Returns TRUE if the specified class name exists on the element.
Parameters:
Name Type Description elementElement The DOMElement to check. classNameString The class name to check. Returns:
TRUE if the specified class name exists on the element.- Type
- boolean
-
(static) insertAfter(element, referenceElement)
-
Inserts the specified node immediately after the reference element.
This convenience method saves the programmer from having to determine whether to call
insertBefore()orappendChild(), depending on whether the reference element is the last child node.Parameters:
Name Type Description elementElement The element to insert. referenceElementElement The reference element to insert the element after. -
(static) isAncestorOfElement(possibleAncestor, possibleChildElement) → {boolean}
-
Checks to see if the specified ancestor element contains the specified child element.
Parameters:
Name Type Description possibleAncestorElement the element that is presumed to be a parent node. possibleChildElementElement the element to start the search at. Returns:
TRUE if the specified ancestor element contains the child element.- Type
- boolean
-
(static) removeChild(childElement)
-
Removes the specified child from its parent.
Parameters:
Name Type Description childElementElement The child to remove. -
(static) removeClassName(element, className)
-
Removes the CSS class name from the specified element.
Parameters:
Name Type Description elementElement The HTML element that the class name should be removed from. classNameString The CSS class to remove from the element. -
(static) replaceClassName(element, currentClassName, newClassName)
-
Replaces the specified CSS class name on the DOM element with another class.
Parameters:
Name Type Description elementElement The HTML DOM element to add the class to. currentClassNameString The class name to replace. newClassNameString The new name of the class. -
(static) setInnerHtml(element, htmlToSet)
-
Sets the innerHTML of the specified element in an efficient way.
Parameters:
Name Type Description elementElement the element on which innerHTMLneeds to be set.htmlToSetString The HTML that will be set in the element. -
(static) setNodeText(element, textToSet)
-
Sets the text contents of the specified element in an efficient way. This function should only be used for setting plain text contents.
Parameters:
Name Type Description elementElement The element on which to set the new text content. textToSetString Text content to set on the element.