DOM Class
DOM methods
Methods
create
(
ElementWrapper | HTMLElement
-
tag -
[properties={}] -
[wrap=true] -
[attributes={}]
Create and return a new wrapped DOM element
Parameters:
-
tagStringTag name to create (eg. "span")
-
[properties={}]Object optionalProperties to set on the new element
-
[wrap=true]Boolean optionalWhether to wrap the element or not. Optional, default is true
-
[attributes={}]Object optionalAttributes to set on the new element
Returns:
ElementWrapper | HTMLElement:
The new element (or a wrapper if wrap is true)
Example:
var newEl = DOM.create('div',
{
id: 'hello-world',
className: 'awesome',
innerHTML: 'This is a test!'
}); // Creates <div id="hello-world" class="awesome">This is a test!</div>
wrap
(
ElementWrapper
-
el
Wrap an element with useful functions. This creates an instance of ElementWrapper
that "wraps" the passed element. The $ method can be used as a shortcut to this.
Parameters:
-
elHTMLElement | ElementWrapper | StringEither the ID of the element, or the element itself
Returns:
ElementWrapper:
An ElementWrapper instance
Example:
var containerEl = DOM.wrap('container'); // Gets the element with an ID of "container"
var containerEl = $('container'); // Exact same as above - $ is an alias for DOM.wrap
wrapAll
(
Array of ElementWrapper
-
input
Wrap all the passed elements
Parameters:
-
inputArray of HTMLElementArray of elements
Returns:
Array of ElementWrapper:
Array of wrapped elements
Example:
// Get all DIVs on the page, and create an ElementWrapper for each
var wrapped = DOM.wrapAll(document.getElementsByTagName('div'));
Properties
cache
Array
private
Cache of ElementWrappers
JS_ELEMENT_ID
Unknown
final
Name of the attribute used to store an element ID number in the cache
