Constructor
new module:br-util /Element Utility()
Methods
(static) add And Remove Class Names(element, classes ToAdd, classes ToRemove)
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 |
---|---|---|
element |
Element | The HTML DOM element to make the class changes to. |
classesToAdd |
Array |
The list of class names that will be added to the list of existing classes. |
classesToRemove |
Array |
The list of class names that will be removed from the list of existing classes. |
(static) add Class Name(element, class Name)
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 |
---|---|---|
element |
Element | The HTML DOM element to add the CSS class to. |
className |
String | The class name that will be added to the list of existing classes. |
(static) discard Child(first Element)
Discards one or more elements (all arguments passed will be discarded) by removing children, and removing it from any parentNode.
Parameters:
Name | Type | Description |
---|---|---|
firstElement |
Element | First Element DOM Element |
(static) get Ancestor Element With Class(element, class Name) → {DOMElement}
Returns the first element that contains the given class as part of its className
string.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | the element to start the search at. |
className |
String | the class name to look for. |
Returns:
The ancestor element with the specified class, or null.
- Type
- DOMElement
(static) get Elements ByClass Name(dom Element, tag Name, class Name) → {Array.< DOMElement>}
Returns an array of DOM elements that match the specified tag name and class name.
Parameters:
Name | Type | Description |
---|---|---|
domElement |
DOMElement | The DOM element that should be used as the root of the search. |
tagName |
String | The tag name (can be *) of elements to search for. |
className |
String | The CSS class name of the elements to search for. |
Returns:
An array of elements that match the specified criteria.
- Type
-
Array
.<DOMElement>
(static) get Node Index(element)
Returns the node index of the element as it exists in the parent.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The element to get the index for. |
Throws:
Error If the specified element does not have a parent.
Returns:
the node index
(static) get Position(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 |
---|---|---|
elem |
DOMElement | The DOM element to calculate the position of |
Returns:
{left:x,top:y}
(static) get Scroll Offset(elem) → {Object}
Returns the scrolled offset of the element (if any) in an object containing a left and top properties.
Parameters:
Name | Type | Description |
---|---|---|
elem |
Element | The DOM element to calculate the scrolled offset of. |
Returns:
{left:x,top:y}
- Type
- Object
(static) get Size(elem)
Returns the bounding rectangle of the specified element.
Parameters:
Name | Type | Description |
---|---|---|
elem |
Object | The element to get the bounding rectangle for. |
Returns:
{left:x,right:y}
(static) has Class Name(element, class Name) → {boolean}
Returns TRUE if the specified class name exists on the element.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The DOMElement to check. |
className |
String | The class name to check. |
Returns:
TRUE if the specified class name exists on the element.
- Type
- boolean
(static) insert After(element, reference Element)
Inserts the specified node immediately after the reference element.
This convenience method saves the programmer from having to determine whether to call insertBefore()
or appendChild()
, depending on whether the reference element is the last child node.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The element to insert. |
referenceElement |
Element | The reference element to insert the element after. |
(static) is Ancestor OfElement(possible Ancestor, possible Child Element) → {boolean}
Checks to see if the specified ancestor element contains the specified child element.
Parameters:
Name | Type | Description |
---|---|---|
possibleAncestor |
Element | the element that is presumed to be a parent node. |
possibleChildElement |
Element | the element to start the search at. |
Returns:
TRUE if the specified ancestor element contains the child element.
- Type
- boolean
(static) remove Child(child Element)
Removes the specified child from its parent.
Parameters:
Name | Type | Description |
---|---|---|
childElement |
Element | The child to remove. |
(static) remove Class Name(element, class Name)
Removes the CSS class name from the specified element.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The HTML element that the class name should be removed from. |
className |
String | The CSS class to remove from the element. |
(static) replace Class Name(element, current Class Name, new Class Name)
Replaces the specified CSS class name on the DOM element with another class.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The HTML DOM element to add the class to. |
currentClassName |
String | The class name to replace. |
newClassName |
String | The new name of the class. |
(static) set Inner Html(element, html ToSet)
Sets the innerHTML of the specified element in an efficient way.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | the element on which |
htmlToSet |
String | The HTML that will be set in the element. |
(static) set Node Text(element, text ToSet)
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 |
---|---|---|
element |
Element | The element on which to set the new text content. |
textToSet |
String | Text content to set on the element. |