Utilities for working with the Document Object Model (DOM).
- Source:
Methods
(static) addClass(item, className) → {void}
Adds a class to the specified element.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
item |
String | Element | The selector or element to add the class to. |
className |
String | The class to add. |
Returns:
- Type
- void
DOMUtils.addClass(evt.currentTarget, 'foo');
(static) attr(item, attribute) → {String}
Returns the attribute of the specified element.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
item |
String | Element | The selector or element to query. |
attribute |
String | The attribute to query. |
Returns:
- The value of the attribute.
- Type
- String
DOMUtils.attr('.foo', 'data-baz');
(static) el(selector) → {Element|Array}
Returns the element(s) matching the specified selector.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
selector |
String | The selector of the element to query. |
Returns:
- The element or array of elements matching the selector.
- Type
- Element | Array
DOMUtils.el('.foo');
(static) hasClass(item, className) → {Boolean}
Checks if an element has a specified class.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
item |
String | Element | The selector or element to check. |
className |
String | The class to check for. |
Returns:
- Whether the element has the class or not
- Type
- Boolean
DOMUtils.hasClass(evt.currentTarget, 'foo');
(static) height(item, includeMarginopt, includePaddingopt) → {Number}
Get the height of the specified element.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
String | Element | The selector or element to find the height of. | ||
includeMargin |
Boolean |
<optional> |
true | Whether to include the margins in the calculation effectively getting the outerHeight. |
includePadding |
Boolean |
<optional> |
true | Whether to include the padding in the calculation. |
Returns:
- The height of the element.
- Type
- Number
DOMUtils.height('.foo');
(static) parent(item, parentSelectoropt) → {Element}
Returns the element's parent or the closest ancestor matching the specified selector if provided.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
item |
String | Element | The selector or element to find the parent of. | |
parentSelector |
String |
<optional> |
The selector of the ancestor to find. |
Returns:
- The parent of the item.
- Type
- Element
DOMUtils.parent('.foo', '.bar');
(static) remove(items) → {void}
Removes element(s) from the DOM.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
items |
String | Element | Array | The selector or element(s) to remove from the DOM. |
Returns:
- Type
- void
DOMUtils.remove('.class-to-remove');
(static) removeClass(item, className) → {void}
Removes a class from the specified element.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
item |
String | Element | The selector or element to remove the class from. |
className |
String | The class to remove. |
Returns:
- Type
- void
DOMUtils.removeClass(evt.currentTarget, 'foo');
(static) tag(el, lowercaseopt) → {String}
Returns the tag name of the specified element.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
el |
Element | The element to check the tag of. | ||
lowercase |
Boolean |
<optional> |
true | Whether to normalize the tag name for comparison as lowercase. |
Returns:
- The tag of the specified element.
- Type
- String
DOMUtils.tag(document.querySelector('.foo'));
(static) width(item, includeMarginopt, includePaddingopt) → {Number}
Get the width of the specified element.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
String | Element | The selector or element to find the width of. | ||
includeMargin |
Boolean |
<optional> |
true | Whether to include the margins in the calculation effectively getting the outerWidth. |
includePadding |
Boolean |
<optional> |
true | Whether to include the padding in the calculation. |
Returns:
- The width of the element.
- Type
- Number
DOMUtils.width('.foo');