The Element API provides useful functions for manipulating and traversing the DOM.
All of these elements are classed under $E. When using the Element or $E function,
all Element functions that have their first argument as element are added to the element.
the HTML Element for the given id with functions in Element. This is also aliased as MVC.$E()
{String/HTMLElement} - Either an HTMLElement or a string describing the element's id.
Static Methods
add_class
add_class(element, className) -> HTMLElement
Adds a class to the html element.
{HTMLElement} - element that will have a class added to its className
{String} -
{HTMLElement} - element
class_names
class_names(element) -> undefined
Returns a list of classNames
{Array} -
dom/position
compare
compare(a, b) -> Number
Compares the position of two nodes and returns at bitmask detailing how they are positioned
relative to each other. You can expect it to return the same results as
compareDocumentPosition.
Parts of this documentation and source come from John Resig.
{HTMLElement} - the first node
{HTMLElement} - the second node
{Number} - A bitmap with the following digit values:
Bits
Number
Meaning
000000
0
Elements are identical.
000001
1
The nodes are in different documents (or one is outside of a document).
{Function} - if provided should return true or false for the element you want returned
get_children
get_children(element) -> HTMLElement
Returns children with nodeType = 1
{} -
{HTMLElement} -
get_style
get_style(element, style) -> undefined
Returns the style for a given element.
{} -
{} -
has
has(element, b) -> Boolean
Returns true or false if one element is inside another element.
Typically this is called with an element's related target to prevent mouseout from being called
on nested HTML. For example:
MVC.$(event.target).has(event.relatedTarget);
If you need to know more about elements position in the dom, try [MVC.Position.static.compare].
{HTMLElement} - outer element, or element in MVC.$E()
{HTMLElement} - inner element
{Boolean} - Returns true if b is in element, false if otherwise.
has_class
has_class(element, regexp) -> Array
Returns an array of matches if the element has a className, null if otherwise.
{String/HTMLElement} - the element you want the offset of.
{MVC.Vector} - a vector with the top and bottom values.
dom/position
offset
offset(element) -> undefined
Returns the position of the element on the page.
{HTMLElement} -
previous
previous(element, wrap, check) -> undefined
Returns the previous sibling with nodeType = 1
{} -
{} -
{} -
remove_class
remove_class(element, className) -> HTMLElement
Removes a class to the html element.
{HTMLElement} - element that will have a class removed from its className
{String} -
{HTMLElement} - element
toggle
toggle(element) -> String
Toggles the style display. It is assumed that no css is already being used to
hide the element. If you want to have the element hidden to start, write
style="display:none" in your html.
{} -
{String} - the resulting display name. '' if visible, 'none' if hidden.
update
update(element, content) -> HTMLElement
Updates an element with content. This is a cross browser substitute for innerHTML.
It very valuable when inserting new table elements.
{HTMLElement} - the element you want updated
{String} - html content
{HTMLElement} - element.
dom/position
window_dimensions
window_dimensions() -> Object
Returns an object with important position and dimension information on the document and window.
{Object} -
dom/position
within
within(element, x, y, cache) -> Boolean
Returns if a coordinate is within an element taking scrolling into account.
{HTMLElement} -
{Number} - pixels on the page
{Number} - pixels on the page
{Boolean} - If present, an object that will be used to cache position lookups
{Boolean} - true if x, y is inside the element, false if otherwise.