Class o2.Dom
static
class
o2.Dom
Activates the alternate stylesheet with the given
title
.
Usage example:
o2.Dom.activateAlternateStylesheet('alternateTheme');
Add a class to the given node.
Usage example:
o2.Dom.addClass('container', 'active');
Adds the CSS rules given in the cssText parameter to the document.
Usage example:
o2.Dom.addCssRules( 'div.warning { background-color:#c00; color:#fff };' );
Adds style attributes to a DOM
node.
Note that adding and removing style attributes to a DOM not is considered "bad practice". Do not use inline styles to modify the view; assign className's instead of style values.
Usage example:
o2.Dom.addStyle('container', {color : '#bada55'})
Appends the element to the bottom of its parent.
Usage example:
var child = o2.$('childNode'); var parent = o2.$('parentNode'); o2.Dom.append(child, parent);
Trims a given field, and returns the compacted value.
Usage example:
o2.Dom.compactField('txtInput');
An alias to o2.Dom.createElement.
Creates a regular expression that will match a given CSS class name.
Usage example:
var reg = o2.Dom.createClassNameRegExp('testClass');
Creates a Document Fragment from an
HTML String
.
Usage example:
var frag = o2.Dom.createDocumentFragment('[div]test[/div]');
Creates an element with given name and attributes.
Usage example:
var el = o2.Dom.createElement( 'div', {className : 'active', style : 'font-weight : bold'} );
An alias to o2.Dom.removeChildren.
Gets the attribute of a given node.
Usage example:
var uid = o2.Dom.getAttribute('container', 'data-user-id');
Gets the children of the element until a given node (exclusive).
Usage example:
var items = o2.Dom.getChildrenByAttributeUntil('container', 'data-user-id', '42', o2.$('stopper'), 'li');
Gets the children of the element having a specific class.
Usage example:
var items = o2.Dom.getChildrenByClass('container', 'active', 'li');
Gets the children of the element having a specific class, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenByClassUntil('container', 'active', o2.$('stopper'), 'li');
Gets the children of the element until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenUntil('container', o2.$('stopper'), 'li');
Gets the children of the element having a given attribute defined.
Usage example:
var items = o2.Dom.getChildrenWithAttribute('container', 'data-user-id', 'li');
Gets the children of the element with a given attribute defined, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenWithAttributeUntil('content', 'data-user-id', o2.$('stopper'), 'li');
Gets the children of the element with a "class" attribute defined.
Usage example:
var items = o2.Dom.getChildrenWithClass('content', 'selected', 'li');
Gets the children of the element with a "class" attribute defined, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenWithClassUntil('content', 'stopper', 'li');
Gets the children of the element with an "id" attribute defined.
Usage example:
var items = o2.Dom.getChildrenWithId('content', 'li');
Gets the children of the element with an "id" attribute defined, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenWithIdUntil('content', 'stopper', 'li');
An alias to o2.Dom.getStyle.
Gets the dimension of the given element in the form
{width: w, height: h}
, where w and
h are in pixels.
Usage example:
var dimensions = o2.Dom.getDimension('container');
Gets the dimension of the document in the form {width: w,
height: h}
. If the visible (i.e. clientHeight
) is
greater than the document's height returns the height of the visible
area as the height portion.
Usage example:
var viewportInfo = o2.Dom.getDocumentDimension();
Gets the total height of the document in pixels.
Usage example:
var viewportHeight = o2.Dom.getDocumentHeight();
Gets the total width of the document in pixels.
Usage example:
var viewportWidth = o2.Dom.getDocumentWidth();
Gets all of the elements of the node elm.
Usage example:
var items = o2.Dom.getElements('content', 'li');
Gets all of the elements of the node elm, filtering the nodes having a given attribute equals to a given value.
Usage example:
var items = o2.Dom.getElementsByAttribute('content', 'data-id', '42');
Gets all of the elements of the node elm, having a given CSS class name.
Usage example:
var items = o2.Dom.getElementsByClass('content', 'selected', 'li');
Gets all of the elements of the node elm, having a given attribute defined.
Usage example:
var items = o2.Dom.getElementsWithAttribute('content', 'data-id', 'li');
Gets all of the elements of the node elm, having a 'class" attribute defined.
Usage example:
var items = o2.Dom.getElementsWithClass('content', 'li');
Gets all of the elements of the node elm, having an 'id" attribute defined.
Usage example:
var items = o2.Dom.getElementsWithId('content', 'li');
Gets the first sibling of the element that's not a text node.
Usage example:
var item = o2.Dom.getFirst('content', 'li');
Gets the first sibling of the element that's not a text node, and having an attibute with a given value.
Usage example:
var item = o2.Dom.getFirstByAttribute('content', 'data-id', '42');
Gets the first sibling of the element that's not a text node, and having a given CSS class name.
Usage example:
var item = o2.Dom.getFirstByClass('content', 'selected', 'li');
Gets the first child of the element that's not a text node.
Usage example:
var item = o2.Dom.getFirstChild('content', 'li');
Gets the first child of the element that's not a text node, and having an attribute with a given value.
Usage example:
var item = o2.Dom.getFirstChildByAttribute('content', 'data-id', '42');
Gets the first child of the element that's not a text node, and having a given class name.
Usage example:
var item = o2.Dom.getFirstChildByClass('content', 'selected', 'li');
Gets the first child of the element that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getFirstChildWithAttribute('content', 'data-id', 'li');
Gets the first child of the element that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getFirstChildWithClass('content', 'li');
Gets the first child of the element that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getFirstChildWithId('content', 'li');
Gets the first sibling of the element that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getFirstWithAttribute('content', 'data-id', 'li');
Gets the first sibling of the element that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getFirstWithClass('content', 'li');
Gets the first sibling of the element that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getFirstWithId('content', 'li');
Gets the height of the given element, in pixels.
Usage example:
var containerHeight = o2.Dom.getHeight('container');
Gets the HTML of a given element.
Usage example:
var html = o2.Dom.getHtml('container');
Gets the last sibling of the element that's not a text node.
Usage example:
var item = o2.Dom.getLast('content', 'li');
Gets the last sibling of the element that's not a text node, and has an attribute with a given value.
Usage example:
var item = o2.Dom.getLastByAttribute('content', 'data-id', '42');
Gets the last sibling of the element that's not a text node, and has a given class name.
Usage example:
var item = o2.Dom.getLastByClass('content', 'selected', 'li');
Gets the last child of the element that's not a text node.
Usage example:
var item = o2.Dom.getLastChild('content', 'li');
Gets the last child of the element that's not a text node, and having an attribute with a given value.
Usage example:
var item = o2.Dom.getLastChildByAttribute('content', 'data-id', '42');
Gets the last child of the element that's not a text node, and having a given CSS class name.
Usage example:
var item = o2.Dom.getLastChildByClass('content', 'selected', 'li');
Gets the last child of the element that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getLastChildWithAttribute('content', 'data-id', 'li');
Gets the last child of the element that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getLastChildWithClass('content', 'selected', 'li');
Gets the last child of the element that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getLastChildWithId('content', 'li');
Gets the last sibling of the element that's not a text node, and has a given attribute defined.
Usage example:
var item = o2.Dom.getLastWithAttribute('content', 'data-id', 'li');
Gets the last sibling of the element that's not a text node, and has a "class" attribute defined.
Usage example:
var item = o2.Dom.getLastWithClass('content', 'selected', 'li');
Gets the last sibling of the element that's not a text node, and has an "id" attribute defined.
Usage example:
var item = o2.Dom.getLastWithId('content', 'li');
Gets the next sibling of the element, that's not a text node.
Usage example:
var item = o2.Dom.getNext('content', 'li');
Gets all the following siblings of the element that are not text nodes.
Usage example:
var item = o2.Dom.getNextAll('content', 'li');
Gets all the following siblings of the element that are not text nodes, having an attribute with a given value.
Usage example:
var item = o2.Dom.getNextAllByAttribute('content', 'data-id', '42');
Gets all the following siblings of the element that are not text nodes, having an attribute with a given value, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
Gets all the following siblings of the element that are not text nodes, having a given CSS class name.
Usage example:
var item = o2.Dom.getNextAllByClass('content', 'selected', 'li');
Gets all the following siblings of the element that are not text nodes, having a given CSS class name, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllByClassUntil('content', 'selected', 'stopper', 'li');
Gets all the following siblings of the element that are not text nodes, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllUntil('content', 'stopper', 'li');
Gets all the following siblings of the element that are not text nodes, having a given attribute defined.
Usage example:
var item = o2.Dom.getNextAllWithAttribute('content', 'data-id', 'li');
Gets all the following siblings of the element that are not text nodes, having a given attribute defined, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllWithAttributeUntil('content', 'data-id', 'stopper', 'li');
Gets all the following siblings of the element that are not text nodes, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNextAllWithClass('content', 'li');
Gets all the following siblings of the element that are not text nodes, having a "class" attribute defined, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllWithClassUntil('content', 'stopper', 'li');
Gets all the following siblings of the element that are not text nodes, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNextAllWithId('content', 'li');
Gets all the following siblings of the element that are not text nodes, having an "id" attribute defined, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllWithIdUntil('content', 'stopper', 'li');
Gets the next sibling of the element, that's not a text node, and having an attribute with a given value.
Usage example:
var item = o2.Dom.getNextByAttribute('content', 'data-id', '42', 'li');
Usage example:
var item = o2.Dom.getNextByClass('content', 'selected', 'li');
Gets the next sibling of the element, that's not a text node, and having a given CSS class name.
Gets the next sibling of the element, that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getNextWithAttribute('content', 'data-id', 'li');
Gets the next sibling of the element, that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNextWithClass('content', 'li');
Gets the next sibling of the element, that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNextWithId('content', 'li');
Gets nth non-text-node sibling of an element, starting from the first sibling.
Usage example:
var item = o2.Dom.getNth('content', 42, 'li');
Gets nth non-text-node sibling of an element, starting from the first sibling, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthByAttribute('content', 'data-id', '42', 42);
Gets nth non-text-node sibling of an element, starting from the first sibling, having a given CSS class name.
Usage example:
var item = o2.Dom.getNthByAttribute('content', 'selected', 42, 'li');
Gets nth non-text-node child of an element.
Usage example:
var item = o2.Dom.getNthChild('content', 42, 'li');
Gets nth non-text-node child of an element, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthChildByAttribute('content', 'data-id', '42', 42);
Gets nth non-text-node child of an element, having a given attribute with a given CSS class name.
Usage example:
var item = o2.Dom.getNthChildByClass('content', 'selected', 42, 'li');
Gets nth non-text-node child of an element, with a given attribute defined.
Usage example:
var item = o2.Dom.getNthChildWithAttribute('content', 'data-id', 42);
Gets nth non-text-node child of an element, with a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthChildWithClass('content', 42, 'li');
Gets nth non-text-node child of an element, with a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthChildWithId('content', 42, 'li');
Gets nth non-text-node next sibling of an element.
Usage example:
var item = o2.Dom.getNthNext('content', 42, 'li');
Gets nth non-text-node next sibling of an element, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthNextByAttribute('content', 'data-id', '42', 42);
Gets nth non-text-node next sibling of an element, having a given CSS class name.
Usage example:
var item = o2.Dom.getNthNextByClass('content', 'selected', 42, 'li');
Gets nth non-text-node next sibling of an element, having a given attribute defined.
Usage example:
var item = o2.Dom.getNthNextWithAttribute('content', 'data-id', 42);
Gets nth non-text-node next sibling of an element, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthNextWithClass('content', 42, 'li');
Usage example:
var item = o2.Dom.getNthNextWithId('content', 42, 'li');
Gets nth non-text-node next sibling of an element, having an "id" attribute defined.
Gets nth parent node of an element.
Usage example:
var item = o2.Dom.getNthParent('content', 42, 'li');
Usage example:
var item = o2.Dom.getNthParentByAttribute('content', 'data-id', '42', 42, 'li');
Gets nth parent node of an element, having a given attribute with a given value.
Gets nth parent node of an element, having a given class name.
Usage example:
var item = o2.Dom.getNthParentByClass('content', 'selected', 42, 'li');
Gets nth parent node of an element, having a given attribute defined.
Usage example:
var item = o2.Dom.getNthParentWithAttribute('content', 'data-id', 42);
Gets nth parent node of an element, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthParentWithClass('content', 42, 'li');
Gets nth parent node of an element, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNthParentWithId('content', 42, 'li');
Gets nth previous sibling of an element that's not a text node.
Usage example:
var item = o2.Dom.getNthPrev('content', 42, 'li');
Gets nth previous sibling of an element that's not a text node, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthPrevByAttribute('content', 'data-id', '42', 42, 'li');
Gets nth previous sibling of an element that's not a text node, having a given CSS class name.
Usage example:
var item = o2.Dom.getNthPrevByClass('content', 'selected', 42, 'li');
Gets nth previous sibling of an element that's not a text node, having a given attribute defined.
Usage example:
var item = o2.Dom.getNthPrevWithAttribute('content', 'data-id', 42);
Gets nth previous sibling of an element that's not a text node, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthPrevWithClass('content', 42, 'li');
Gets nth previous sibling of an element that's not a text node, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNthPrevWithId('content', 42, 'li');
Usage example:
var item = o2.Dom.getNthWithAttribute('content', 'data-id', 42, 'li');
Gets nth non-text-node sibling of an element, starting from the first sibling, having a given attribute defined.
Gets nth non-text-node sibling of an element, starting from the first sibling, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthWithClass('content', 42, 'li');
Usage example:
var item = o2.Dom.getNthWithId('content', 42, 'li');
Gets nth non-text-node sibling of an element, starting from the first sibling, having an "id" attribute defined.
Gets the DOM object's scroll offset.
Usage example:
var offsets = o2.Dom.getObjectScrollOfset('container');
An alias to o2.Dom.getOffset(obj).left
.
An alias to o2.Dom.getOffset(obj).top
.
Gets the parent node of an element.
Usage example:
var item = o2.Dom.getParent('content', 'li');
Gets the parent node of an element, having an attribute with a given value.
Usage example:
var item = o2.Dom.getParentByAttribute('content', 'data-id', '42', 'li');
Gets the parent node of an element, having a given CSS class name.
Usage example:
var item = o2.Dom.getParentByClass('content', 'selected', 'li');
Gets the parent node of an element, having a given attribute defined.
Usage example:
var item = o2.Dom.getParentWithAttribute('content', 'selected', 'li');
Gets the parent node of an element, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getParentWithClass('content', 'li');
Gets the parent node of an element, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getParentWithId('content', 'li');
Gets all the parent nodes of an element.
Usage example:
var items = o2.Dom.getParents('content', 'li');
Gets all the parent nodes of an element, having a given attribute with a given value.
Usage example:
var items = o2.Dom.getParentsByAttribute('content', 'data-id', '42');
Gets all the parent nodes of an element, having a given attribute with a given value, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
Gets all the parent nodes of an element, having a given CSS class name.
Usage example:
var items = o2.Dom.getParentsByClass('content', 'selected', 'li');
Gets all the parent nodes of an element, having a given CSS class name, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsByClassUntil('content', 'selected', 'stopper', 'li');
Gets all the parent nodes of an element, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsUntil('content', 'stopper', 'li');
Gets all the parent nodes of an element, having a given attribute defined.
Usage example:
var items = o2.Dom.getParentsWithAttribute('content', 'data-id', 'li');
Gets all the parent nodes of an element, having a given attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsWithAttributeUntil('content', 'data-id', 'stopper', 'li');
Gets all the parent nodes of an element, having a "class" attribute defined.
Usage example:
var items = o2.Dom.getParentsWithClass('content', 'li');
Gets all the parent nodes of an element, having a "class" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsWithClass('content', 'stopper', 'li');
Gets all the parent nodes of an element, having an "id" attribute defined.
Usage example:
var items = o2.Dom.getParentsWithId('content', 'li');
Gets all the parent nodes of an element, having an "id" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsWithIdUntil('content', 'stopper', 'li');
Gets the previous sibling of an element that's not a text node.
Usage example:
var item = o2.Dom.getPrev('content', 'li');
Gets all previous sibling of an element, that are not text nodes.
Usage example:
var items = o2.Dom.getPrevAll('content', 'li');
Gets all previous sibling of an element, that are not text nodes, having a given attribute with a given value.
Usage example:
var items = o2.Dom.getPrevAllByAttribute('content', 'data-id', '42');
Gets all previous sibling of an element, that are not text nodes, having a given attribute with a given value, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
Gets all previous sibling of an element, that are not text nodes, having a given CSS class name.
Usage example:
var items = o2.Dom.getPrevAllByClass('content', 'selected', 'li');
Gets all previous sibling of an element, that are not text nodes, having a given CSS class name, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllByClassUntil('content', 'selected', 'stopper', 'li');
Gets all previous sibling of an element, that are not text nodes, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllUntil('content', 'stopper', 'li');
Gets all previous sibling of an element, that are not text nodes, having a given attribute defined.
Usage example:
var items = o2.Dom.getPrevAllWithAttribute('content', 'data-id', 'li');
Gets all previous sibling of an element, that are not text nodes, having a given attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllWithAttributeUntil('content', 'data-id', 'stopper', 'li');
Gets all previous sibling of an element, that are not text nodes, having a "class" attribute defined.
Usage example:
var items = o2.Dom.getPrevAllWithClass('content', 'li');
Gets all previous sibling of an element, that are not text nodes, having a "class" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllWithClassUntil('content', 'stopper', 'li');
Gets all previous sibling of an element, that are not text nodes, having an "id" attribute defined.
Usage example:
var items = o2.Dom.getPrevAllWithId('content', 'li');
Gets all previous sibling of an element, that are not text nodes, having an "id" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllWithIdUntil('content', 'stopper', 'li');
Gets the previous sibling of an element that's not a text node, having an attribute with a given value.
Usage example:
var item = o2.Dom.getPrevByAttribute('content', 'data-id', '42', 'li');
Gets the previous sibling of an element that's not a text node, having a given CSS class name.
Usage example:
var item = o2.Dom.getPrevByClass('content', 'selected', 'li');
Gets the previous sibling of an element that's not a text node, having a given attribute defined.
Usage example:
var item = o2.Dom.getPrevWithAttribute('content', 'data-id', 'li');
Gets the previous sibling of an element that's not a text node, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getPrevWithClass('content', 'selected', 'li');
Gets the previous sibling of an element that's not a text node, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getPrevWithId('content', 'selected', 'li');
An alias to o2.Dom.getObjectStrollOffset.
Gets the siblings of the element.
Usage example:
var items = o2.Dom.getSiblings('content', 'li');
Gets the siblings of the element, having a given attribute equals a given value.
Usage example:
var items = o2.Dom.getSiblingsByAttribute('content', 'data-id', '42');
Gets the siblings of the element, having a given attribute equals a given value, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
Gets the siblings of the element, having a given class name.
Usage example:
var items = o2.Dom.getSiblingsByClass('content', 'selected', 'li');
Gets the siblings of the element, having a given class name, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsByClassUntil('content', 'selected', 'stopper', 'li');
Gets the siblings of the element until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsUntil('content', 'stopper', 'li');
Gets the siblings of the element, having a given attribute defined.
Usage example:
var items = o2.Dom.getSiblingsWithAttribute('content', 'dada-id', 'li');
Gets the siblings of the element, having a given attribute defined, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsWithAttributeUntil('content', 'data-id', 'stopper', 'li');
Gets the siblings of the element, having "class" attribute defined.
Usage example:
var items = o2.Dom.getSiblingsWithClass('content', 'li');
Gets the siblings of the element, having a "class" attribute defined, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsWithClassUntil('content', 'stopper', 'li');
Gets the siblings of the element, having an "id" attribute defined.
Usage example:
var items = o2.Dom.getSiblingsWithId('content', 'li');
Usage example:
var items = o2.Dom.getSiblingsWithIdUntil('content', 'stopper', 'li');
Gets the siblings of the element, having an "id" attribute defined, until (but not included to) a specific node.
Gets the style of a given property of the element.
Tries to parse the currentStyle
, if available;
otherwise tries to calculate the style using
window.getComputedStyle
;
gets obj.style
if everything else fails.
Note that adding and removing style attributes to a DOM not is considered "bad practice". Do not use inline styles to modify the view; assign className's instead of style values.
Usage example:
var color = o2.Dom.getStyle('container', 'color');
Gets the textual content of the given node, replacing entities
like & amp;
with it's corresponding character
counterpart (& in this example).
Usage example:
var txt = o2.Dom.getText('container');
Gets the viewport information in the form
{scrollTop : #, scrollLeft: #, width: #, height: #}
.
Usage example:
var details = o2.Dom.getViewportInfo();
Gets the dimension of the visible area of the browser in the form
{width: w, height: h}
.
Usage example:
var windowDimensions = o2.Dom.getWindowInnerDimension();
Gets the inner height of the visible area.
Usage example:
var innerHeight = o2.Dom.getWindow.innerHeight();
Gets the inner width of the visible area.
Usage example:
var innerWidth = o2.Dom.getWindowInnerWidth();
Gets the window's scroll offset.
Usage example:
var offsets = o2.Dom.getWindowScrollOffset();
Checks whether an element has the given className.
Usage example:
if (o2.Dom.hasClass('container', 'active')) { doStuff(); }
Adds the node after the reference node.
Usage example:
var ref = o2.$('ref'); var new = o2.$('new'); o2.Dom.insertAfter(new, ref);
Adds the node before the reference node.
Usage example:
var ref = o2.$('ref'); var new = o2.$('new'); o2.Dom.insertBefore(new, ref);
Checks whether elm is the child of ref.
Usage example:
var isChild = o2.Dom.isChild('child', 'parent');
Checks whether the given node is a document
node.
Usage example:
var isDocument = o2.Dom.isDocument(currentNode);
Checks whether the given node is an element node.
Usage example:
var isElement = o2.Dom.isElement(currentNode);
Checks whether elm is a sibling after ref.
Usage example:
var isNext = o2.Dom.isNext('itemId', 'refId');
Checks whether elm is a parent of ref.
Usage example:
var isParent = o2.Dom.isParent('itemId', 'refId');
Checks whether elm is parent of ref, or it's the ref itself.
Usage example:
var isParent = o2.Dom.isParentOrSelf('itemId', 'refId');
Checks whether elm is a sibling before ref.
Usage example:
var isParent = o2.Dom.isPrev('itemId', 'refId');
Checks whether elm is a sibling of ref.
Usage example:
var isSibling = o2.Dom.isSibling('itemId', 'refId');
Checks whether the DOM node is visible.
Note that being visible does not necessarily mean being available inside the viewport.
If a DOM node has display == 'none'
or visibility == 'hidden'
CSS properties,
then it's regarded as "invisible", otherwise it is considered to be
"visible".
Usage example:
var isContainerVisible = o2.Dom.isVisible('container');
Asynchronously loads a css file with a given src.
Cross-domain loading is also okay: The css file does not have to be in the same domain as the web page.
The success and failure callbacks is a somewhat hacky way of handling CSS load events. In deed, detecting CSS load is not an easy task, and it's not necessary most of the time.
Though it may get handy to prevent the Flash of Unstyled Content (FOUC) issues.
A more robust way of handling load callbacks is polling the property of a test element (such as the background color), that you know that the loaded CSS will change for sure.
Usage example:
o2.Dom.loadCss('http://cdn.example/com/theme.css', function() { handleSuccess(); });
Tries to load the image into a JavaScript
Image
object; then triggers
successCallback
or failureCallback
depending on
the
result of the load attempt.
This function can be used for pre-loading or post-loading images.
Usage example:
o2.Dom.loadImage('http//asset.example.com/spinner.png', function() { handleSuccess(); });
Asynchronously loads a script with a given src.
Cross-domain loading is also okay: The script does not have to be in the same domain as the web page.
Usage example:
o2.Dom.loadImage('http//asset.example.com/script.js', function() { handleSuccess(); });
Prepends the element to the top of its parent.
Usage example:
var child = o2.$('ChildContainer'); var parent = o2.$('MasterContainer'); o2.Dom.prepend(child, parent);
Prevents the form to re-submit itself when the submit button is pressed more than once.
Usage example:
o2.Dom.preventMultipleSubmit('actionForm');
Fires when the HTML DOM
is ready.
Usage example:
o2.Dom.ready(function() { doInitializaton(); });
Removes the element from the DOM flow.
Usage example:
o2.Dom.remove('nagivation');
Removes all the children of the element.
Usage example:
o2.Dom.removeChildren('container');
Removes a class name from the given node.
Usage example:
o2.Dom.removeClass('container', 'active');
An alias to o2.Dom.removeEmptyTextNodes.
Removes empty text nodes from the element.
Note that this removal is not recursive; only the first-level empty child nodes of the element will be removed.
Usage example:
o2.Dom.removeEmptyTextNodes('container');
An alias to o2.Dom.remove.
Replaces one node with another.
Usage example:
o2.Dom.replace('firstContainer', 'secondContainer');
Scrolls an element to bottom.
Usage example:
o2.Dom.scrollObjectToBottom('container');
Scrolls an element to top.
Usage example:
o2.Dom.scrollObjectToTop('container');
An alias to o2.Dom.scrollWindowToObject.
An alias to o2.Dom.scrollWindowToObject.
Usage example:
o2.Dom.scrollWindowToBottom();
Scrolls window to bottom.
An alias to o2.Dom.scrollWindowToObject.
Usage example:
o2.Dom.scrollWindowToTop();
Scrolls window to top.
Sets the attribute of the given object.
Usage example:
o2.Dom.setAttribute('container', 'data-user-id', '123');
An alias to o2.Dom.addStyle.
Sets the dimension of the given element.
Usage example:
o2.Dom.setDimension('container', {width: 400, height: 200});
Sets the height of the given element.
Usage example:
o2.Dom.setHeight('container', 300);
Simply sets the innerHTML
of the element.
Usage example:
o2.Dom.setHtml('container', '[h1]hello[/h1]');
An alias to o2.Dom.addStyle.
Sets the width of the given element.
Usage example:
o2.Dom.setWidth('container', 500);
Toggles the CSS className
of a given
element.
Usage example:
o2.Dom.toggleClass('container', 'active');
Toggles the visibility of the given element.
Usage example:
o2.Dom.toggleVisibility('container');
Trims a given field, and returns the trimmed value.
Usage example:
o2.Dom.trimField('txtInput');
This is like o2.Dom.wrap in reverse.
Moves all the elements inside the container to the container's position and removes the container from the DOM.
Usage example:
o2.Dom.unwrap('container');
Function Details
function activateAlternateStylesheet
static
activateAlternateStylesheet(String
title)
Activates the alternate stylesheet with the given
title
.
Usage example:
o2.Dom.activateAlternateStylesheet('alternateTheme');
title
- the title
of the alternate
stylesheet to activate. function addClass
static
addClass(DomNode
el, String
c)
Add a class to the given node.
Usage example:
o2.Dom.addClass('container', 'active');
el
- either the element, or the
id of it.
c
- the className to add. function addCssRules
static
addCssRules()
Adds the CSS rules given in the cssText parameter to the document.
Usage example:
o2.Dom.addCssRules( 'div.warning { background-color:#c00; color:#fff };' );
function addStyle
Adds style attributes to a DOM
node.
Note that adding and removing style attributes to a DOM not is considered "bad practice". Do not use inline styles to modify the view; assign className's instead of style values.
Usage example:
o2.Dom.addStyle('container', {color : '#bada55'})
obj
- the current DOM
node, or the
id of that node, to add styles to.
style
- styles in the form {style1:value1,
style2:value2}
. function append
Appends the element to the bottom of its parent.
Usage example:
var child = o2.$('childNode'); var parent = o2.$('parentNode'); o2.Dom.append(child, parent);
elmChild
- the child node, or the id of
the node to append.
elmParent
- the parent container, or the
id of the container. function compactField
static
compactField(Object
field)
Trims a given field, and returns the compacted value.
Usage example:
o2.Dom.compactField('txtInput');
field
- the field to be compacted, or its
id. null
if the field
does not exist.
function create
static
create()
An alias to o2.Dom.createElement.
function createClassNameRegExp
static
createClassNameRegExp(String
c)
Creates a regular expression that will match a given CSS class name.
Usage example:
var reg = o2.Dom.createClassNameRegExp('testClass');
c
- The name of the class. RegExp
that matches the given class name.
function createDocumentFragment
static
createDocumentFragment(String
html)
Creates a Document Fragment from an
HTML String
.
Usage example:
var frag = o2.Dom.createDocumentFragment('[div]test[/div]');
html
- the HTML to create a fragment
from. document
fragment.
function createElement
Creates an element with given name and attributes.
Usage example:
var el = o2.Dom.createElement( 'div', {className : 'active', style : 'font-weight : bold'} );
name
- the node name of the element (i.e. 'div', 'a').
attributes
- an associative array in the form
{att1:value1, att2:value2}
. function empty
static
empty(Object
elm)
An alias to o2.Dom.removeChildren.
elm
- either the element, or the
id of it to process. function getAttribute
Gets the attribute of a given node.
Usage example:
var uid = o2.Dom.getAttribute('container', 'data-user-id');
elm
- the node, or the id of the
node, to get the attribute of.
attribute
- the attribute to gather. null
otherwise.
function getChildrenByAttributeUntil
static
getChildrenByAttributeUntil(Object
elm, String
attribute, String
value, Object
until, String
name)
Gets the children of the element until a given node (exclusive).
Usage example:
var items = o2.Dom.getChildrenByAttributeUntil('container', 'data-user-id', '42', o2.$('stopper'), 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenByClass
Gets the children of the element having a specific class.
Usage example:
var items = o2.Dom.getChildrenByClass('container', 'active', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to
undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenByClassUntil
Gets the children of the element having a specific class, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenByClassUntil('container', 'active', o2.$('stopper'), 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenUntil
Gets the children of the element until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenUntil('container', o2.$('stopper'), 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenWithAttribute
Gets the children of the element having a given attribute defined.
Usage example:
var items = o2.Dom.getChildrenWithAttribute('container', 'data-user-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenWithAttributeUntil
Gets the children of the element with a given attribute defined, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenWithAttributeUntil('content', 'data-user-id', o2.$('stopper'), 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenWithClass
Gets the children of the element with a "class" attribute defined.
Usage example:
var items = o2.Dom.getChildrenWithClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenWithClassUntil
Gets the children of the element with a "class" attribute defined, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenWithClassUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenWithId
Gets the children of the element with an "id" attribute defined.
Usage example:
var items = o2.Dom.getChildrenWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getChildrenWithIdUntil
Gets the children of the element with an "id" attribute defined, and until (but not included to) a given element.
Usage example:
var items = o2.Dom.getChildrenWithIdUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getCss
static
getCss()
An alias to o2.Dom.getStyle.
function getDimension
static
getDimension(Object
obj)
Gets the dimension of the given element in the form
{width: w, height: h}
, where w and
h are in pixels.
Usage example:
var dimensions = o2.Dom.getDimension('container');
obj
- the DOMNode to get the dimension
of, or the String
id of it. {width: w, height: h}
.
function getDocumentDimension
static
getDocumentDimension()
Gets the dimension of the document in the form {width: w,
height: h}
. If the visible (i.e. clientHeight
) is
greater than the document's height returns the height of the visible
area as the height portion.
Usage example:
var viewportInfo = o2.Dom.getDocumentDimension();
{width: w,
height: h}
.
function getDocumentHeight
static
getDocumentHeight()
Gets the total height of the document in pixels.
Usage example:
var viewportHeight = o2.Dom.getDocumentHeight();
function getDocumentWidth
static
getDocumentWidth()
Gets the total width of the document in pixels.
Usage example:
var viewportWidth = o2.Dom.getDocumentWidth();
function getElements
Gets all of the elements of the node elm.
Usage example:
var items = o2.Dom.getElements('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getElementsByAttribute
Gets all of the elements of the node elm, filtering the nodes having a given attribute equals to a given value.
Usage example:
var items = o2.Dom.getElementsByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getElementsByClass
Gets all of the elements of the node elm, having a given CSS class name.
Usage example:
var items = o2.Dom.getElementsByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getElementsWithAttribute
Gets all of the elements of the node elm, having a given attribute defined.
Usage example:
var items = o2.Dom.getElementsWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getElementsWithClass
Gets all of the elements of the node elm, having a 'class" attribute defined.
Usage example:
var items = o2.Dom.getElementsWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getElementsWithId
Gets all of the elements of the node elm, having an 'id" attribute defined.
Usage example:
var items = o2.Dom.getElementsWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getFirst
Gets the first sibling of the element that's not a text node.
Usage example:
var item = o2.Dom.getFirst('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstByAttribute
Gets the first sibling of the element that's not a text node, and having an attibute with a given value.
Usage example:
var item = o2.Dom.getFirstByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstByClass
Gets the first sibling of the element that's not a text node, and having a given CSS class name.
Usage example:
var item = o2.Dom.getFirstByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstChild
Gets the first child of the element that's not a text node.
Usage example:
var item = o2.Dom.getFirstChild('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstChildByAttribute
Gets the first child of the element that's not a text node, and having an attribute with a given value.
Usage example:
var item = o2.Dom.getFirstChildByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstChildByClass
Gets the first child of the element that's not a text node, and having a given class name.
Usage example:
var item = o2.Dom.getFirstChildByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstChildWithAttribute
Gets the first child of the element that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getFirstChildWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstChildWithClass
Gets the first child of the element that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getFirstChildWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstChildWithId
Gets the first child of the element that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getFirstChildWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstWithAttribute
Gets the first sibling of the element that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getFirstWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstWithClass
Gets the first sibling of the element that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getFirstWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getFirstWithId
Gets the first sibling of the element that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getFirstWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getHeight
static
getHeight(Object
obj)
Gets the height of the given element, in pixels.
Usage example:
var containerHeight = o2.Dom.getHeight('container');
obj
- the DOMNode to get the dimension
of, or the String
id of it. function getHtml
static
getHtml(Object
elm)
Gets the HTML of a given element.
Usage example:
var html = o2.Dom.getHtml('container');
elm
- the DOM node or its
String
id. innerHTML
of the given node, if it exists;
null
otherwise.
function getLast
Gets the last sibling of the element that's not a text node.
Usage example:
var item = o2.Dom.getLast('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastByAttribute
Gets the last sibling of the element that's not a text node, and has an attribute with a given value.
Usage example:
var item = o2.Dom.getLastByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastByClass
Gets the last sibling of the element that's not a text node, and has a given class name.
Usage example:
var item = o2.Dom.getLastByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastChild
Gets the last child of the element that's not a text node.
Usage example:
var item = o2.Dom.getLastChild('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastChildByAttribute
Gets the last child of the element that's not a text node, and having an attribute with a given value.
Usage example:
var item = o2.Dom.getLastChildByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastChildByClass
Gets the last child of the element that's not a text node, and having a given CSS class name.
Usage example:
var item = o2.Dom.getLastChildByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastChildWithAttribute
Gets the last child of the element that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getLastChildWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastChildWithClass
Gets the last child of the element that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getLastChildWithClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastChildWithId
Gets the last child of the element that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getLastChildWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastWithAttribute
Gets the last sibling of the element that's not a text node, and has a given attribute defined.
Usage example:
var item = o2.Dom.getLastWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastWithClass
Gets the last sibling of the element that's not a text node, and has a "class" attribute defined.
Usage example:
var item = o2.Dom.getLastWithClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getLastWithId
Gets the last sibling of the element that's not a text node, and has an "id" attribute defined.
Usage example:
var item = o2.Dom.getLastWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNext
Gets the next sibling of the element, that's not a text node.
Usage example:
var item = o2.Dom.getNext('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNextAll
Gets all the following siblings of the element that are not text nodes.
Usage example:
var item = o2.Dom.getNextAll('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllByAttribute
Gets all the following siblings of the element that are not text nodes, having an attribute with a given value.
Usage example:
var item = o2.Dom.getNextAllByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllByAttributeUntil
static
getNextAllByAttributeUntil(Object
elm, String
attribute, String
value, Object
until, String
name)
Gets all the following siblings of the element that are not text nodes, having an attribute with a given value, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllByClass
Gets all the following siblings of the element that are not text nodes, having a given CSS class name.
Usage example:
var item = o2.Dom.getNextAllByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllByClassUntil
Gets all the following siblings of the element that are not text nodes, having a given CSS class name, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllByClassUntil('content', 'selected', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllUntil
Gets all the following siblings of the element that are not text nodes, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllWithAttribute
Gets all the following siblings of the element that are not text nodes, having a given attribute defined.
Usage example:
var item = o2.Dom.getNextAllWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllWithAttributeUntil
Gets all the following siblings of the element that are not text nodes, having a given attribute defined, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllWithAttributeUntil('content', 'data-id', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllWithClass
Gets all the following siblings of the element that are not text nodes, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNextAllWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllWithClassUntil
Gets all the following siblings of the element that are not text nodes, having a "class" attribute defined, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllWithClassUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllWithId
Gets all the following siblings of the element that are not text nodes, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNextAllWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextAllWithIdUntil
Gets all the following siblings of the element that are not text nodes, having an "id" attribute defined, until (but not included to) a given DOM node.
Usage example:
var item = o2.Dom.getNextAllWithIdUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getNextByAttribute
Gets the next sibling of the element, that's not a text node, and having an attribute with a given value.
Usage example:
var item = o2.Dom.getNextByAttribute('content', 'data-id', '42', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNextByClass
Usage example:
var item = o2.Dom.getNextByClass('content', 'selected', 'li');
Gets the next sibling of the element, that's not a text node, and having a given CSS class name.
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNextWithAttribute
Gets the next sibling of the element, that's not a text node, and having a given attribute defined.
Usage example:
var item = o2.Dom.getNextWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNextWithClass
Gets the next sibling of the element, that's not a text node, and having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNextWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNextWithId
Gets the next sibling of the element, that's not a text node, and having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNextWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNth
Gets nth non-text-node sibling of an element, starting from the first sibling.
Usage example:
var item = o2.Dom.getNth('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthByAttribute
Gets nth non-text-node sibling of an element, starting from the first sibling, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthByAttribute('content', 'data-id', '42', 42);
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthByClass
Gets nth non-text-node sibling of an element, starting from the first sibling, having a given CSS class name.
Usage example:
var item = o2.Dom.getNthByAttribute('content', 'selected', 42, 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthChild
Gets nth non-text-node child of an element.
Usage example:
var item = o2.Dom.getNthChild('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthChildByAttribute
Gets nth non-text-node child of an element, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthChildByAttribute('content', 'data-id', '42', 42);
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthChildByClass
Gets nth non-text-node child of an element, having a given attribute with a given CSS class name.
Usage example:
var item = o2.Dom.getNthChildByClass('content', 'selected', 42, 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthChildWithAttribute
Gets nth non-text-node child of an element, with a given attribute defined.
Usage example:
var item = o2.Dom.getNthChildWithAttribute('content', 'data-id', 42);
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthChildWithClass
Gets nth non-text-node child of an element, with a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthChildWithClass('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthChildWithId
Gets nth non-text-node child of an element, with a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthChildWithId('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthNext
Gets nth non-text-node next sibling of an element.
Usage example:
var item = o2.Dom.getNthNext('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthNextByAttribute
Gets nth non-text-node next sibling of an element, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthNextByAttribute('content', 'data-id', '42', 42);
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthNextByClass
Gets nth non-text-node next sibling of an element, having a given CSS class name.
Usage example:
var item = o2.Dom.getNthNextByClass('content', 'selected', 42, 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthNextWithAttribute
Gets nth non-text-node next sibling of an element, having a given attribute defined.
Usage example:
var item = o2.Dom.getNthNextWithAttribute('content', 'data-id', 42);
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthNextWithClass
Gets nth non-text-node next sibling of an element, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthNextWithClass('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthNextWithId
Usage example:
var item = o2.Dom.getNthNextWithId('content', 42, 'li');
Gets nth non-text-node next sibling of an element, having an "id" attribute defined.
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthParent
Gets nth parent node of an element.
Usage example:
var item = o2.Dom.getNthParent('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthParentByAttribute
Usage example:
var item = o2.Dom.getNthParentByAttribute('content', 'data-id', '42', 42, 'li');
Gets nth parent node of an element, having a given attribute with a given value.
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthParentByClass
Gets nth parent node of an element, having a given class name.
Usage example:
var item = o2.Dom.getNthParentByClass('content', 'selected', 42, 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthParentWithAttribute
Gets nth parent node of an element, having a given attribute defined.
Usage example:
var item = o2.Dom.getNthParentWithAttribute('content', 'data-id', 42);
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthParentWithClass
Gets nth parent node of an element, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthParentWithClass('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthParentWithId
Gets nth parent node of an element, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNthParentWithId('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthPrev
Gets nth previous sibling of an element that's not a text node.
Usage example:
var item = o2.Dom.getNthPrev('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthPrevByAttribute
Gets nth previous sibling of an element that's not a text node, having a given attribute with a given value.
Usage example:
var item = o2.Dom.getNthPrevByAttribute('content', 'data-id', '42', 42, 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthPrevByClass
Gets nth previous sibling of an element that's not a text node, having a given CSS class name.
Usage example:
var item = o2.Dom.getNthPrevByClass('content', 'selected', 42, 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthPrevWithAttribute
Gets nth previous sibling of an element that's not a text node, having a given attribute defined.
Usage example:
var item = o2.Dom.getNthPrevWithAttribute('content', 'data-id', 42);
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthPrevWithClass
Gets nth previous sibling of an element that's not a text node, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthPrevWithClass('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthPrevWithId
Gets nth previous sibling of an element that's not a text node, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getNthPrevWithId('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthWithAttribute
Usage example:
var item = o2.Dom.getNthWithAttribute('content', 'data-id', 42, 'li');
Gets nth non-text-node sibling of an element, starting from the first sibling, having a given attribute defined.
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthWithClass
Gets nth non-text-node sibling of an element, starting from the first sibling, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getNthWithClass('content', 42, 'li');
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getNthWithId
Usage example:
var item = o2.Dom.getNthWithId('content', 42, 'li');
Gets nth non-text-node sibling of an element, starting from the first sibling, having an "id" attribute defined.
elm
- the element reference, or a String
id of it.
n
- the element index.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getObjectScrollOffset
static
getObjectScrollOffset(Object
obj)
Gets the DOM object's scroll offset.
Usage example:
var offsets = o2.Dom.getObjectScrollOfset('container');
obj
- the DOM node to check, or its
String
id. {left: l, top: t}
.
function getOffset
static
getOffset(Object
e)
Gets the left and top offset of a given element.
// * // * // *
e
- the element, or the id of the element, to get
// * the offsets of.
// *
// * {left: l, top: t}
.
// function getOffsetLeft
static
getOffsetLeft()
An alias to o2.Dom.getOffset(obj).left
.
function getOffsetTop
static
getOffsetTop()
An alias to o2.Dom.getOffset(obj).top
.
function getParent
Gets the parent node of an element.
Usage example:
var item = o2.Dom.getParent('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getParentByAttribute
Gets the parent node of an element, having an attribute with a given value.
Usage example:
var item = o2.Dom.getParentByAttribute('content', 'data-id', '42', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getParentByClass
Gets the parent node of an element, having a given CSS class name.
Usage example:
var item = o2.Dom.getParentByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getParentWithAttribute
Gets the parent node of an element, having a given attribute defined.
Usage example:
var item = o2.Dom.getParentWithAttribute('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getParentWithClass
Gets the parent node of an element, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getParentWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getParentWithId
Gets the parent node of an element, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getParentWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getParents
Gets all the parent nodes of an element.
Usage example:
var items = o2.Dom.getParents('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsByAttribute
Gets all the parent nodes of an element, having a given attribute with a given value.
Usage example:
var items = o2.Dom.getParentsByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsByAttributeUntil
static
getParentsByAttributeUntil(Object
elm, String
attribute, String
value, Object
until, String
name)
Gets all the parent nodes of an element, having a given attribute with a given value, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
until
- the DOM node that the traversal
will be made until, or its String
id,
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsByClass
Gets all the parent nodes of an element, having a given CSS class name.
Usage example:
var items = o2.Dom.getParentsByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsByClassUntil
Gets all the parent nodes of an element, having a given CSS class name, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsByClassUntil('content', 'selected', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsUntil
Gets all the parent nodes of an element, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsWithAttribute
Gets all the parent nodes of an element, having a given attribute defined.
Usage example:
var items = o2.Dom.getParentsWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsWithAttributeUntil
Gets all the parent nodes of an element, having a given attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsWithAttributeUntil('content', 'data-id', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsWithClass
Gets all the parent nodes of an element, having a "class" attribute defined.
Usage example:
var items = o2.Dom.getParentsWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsWithClassUntil
Gets all the parent nodes of an element, having a "class" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsWithClass('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsWithId
Gets all the parent nodes of an element, having an "id" attribute defined.
Usage example:
var items = o2.Dom.getParentsWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getParentsWithIdUntil
Gets all the parent nodes of an element, having an "id" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getParentsWithIdUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrev
Gets the previous sibling of an element that's not a text node.
Usage example:
var item = o2.Dom.getPrev('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getPrevAll
Gets all previous sibling of an element, that are not text nodes.
Usage example:
var items = o2.Dom.getPrevAll('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllByAttribute
Gets all previous sibling of an element, that are not text nodes, having a given attribute with a given value.
Usage example:
var items = o2.Dom.getPrevAllByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllByAttributeUntil
static
getPrevAllByAttributeUntil(Object
elm, String
attribute, String
value, Object
until, String
name)
Gets all previous sibling of an element, that are not text nodes, having a given attribute with a given value, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllByClass
Gets all previous sibling of an element, that are not text nodes, having a given CSS class name.
Usage example:
var items = o2.Dom.getPrevAllByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllByClassUntil
Gets all previous sibling of an element, that are not text nodes, having a given CSS class name, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllByClassUntil('content', 'selected', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllUntil
Gets all previous sibling of an element, that are not text nodes, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllWithAttribute
Gets all previous sibling of an element, that are not text nodes, having a given attribute defined.
Usage example:
var items = o2.Dom.getPrevAllWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllWithAttributeUntil
Gets all previous sibling of an element, that are not text nodes, having a given attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllWithAttributeUntil('content', 'data-id', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllWithClass
Gets all previous sibling of an element, that are not text nodes, having a "class" attribute defined.
Usage example:
var items = o2.Dom.getPrevAllWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllWithClassUntil
Gets all previous sibling of an element, that are not text nodes, having a "class" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllWithClassUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllWithId
Gets all previous sibling of an element, that are not text nodes, having an "id" attribute defined.
Usage example:
var items = o2.Dom.getPrevAllWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevAllWithIdUntil
Gets all previous sibling of an element, that are not text nodes, having an "id" attribute defined, until (but not included to) a given node.
Usage example:
var items = o2.Dom.getPrevAllWithIdUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getPrevByAttribute
Gets the previous sibling of an element that's not a text node, having an attribute with a given value.
Usage example:
var item = o2.Dom.getPrevByAttribute('content', 'data-id', '42', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- i the value of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getPrevByClass
Gets the previous sibling of an element that's not a text node, having a given CSS class name.
Usage example:
var item = o2.Dom.getPrevByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
className
- the CSS class name.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getPrevWithAttribute
Gets the previous sibling of an element that's not a text node, having a given attribute defined.
Usage example:
var item = o2.Dom.getPrevWithAttribute('content', 'data-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getPrevWithClass
Gets the previous sibling of an element that's not a text node, having a "class" attribute defined.
Usage example:
var item = o2.Dom.getPrevWithClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getPrevWithId
Gets the previous sibling of an element that's not a text node, having an "id" attribute defined.
Usage example:
var item = o2.Dom.getPrevWithId('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. null
otherwise.
function getScrollOffset
static
getScrollOffset()
An alias to o2.Dom.getObjectStrollOffset.
function getSiblings
Gets the siblings of the element.
Usage example:
var items = o2.Dom.getSiblings('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsByAttribute
Gets the siblings of the element, having a given attribute equals a given value.
Usage example:
var items = o2.Dom.getSiblingsByAttribute('content', 'data-id', '42');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsByAttributeUntil
static
getSiblingsByAttributeUntil(Object
elm, String
attribute, String
value, Object
until, String
name)
Gets the siblings of the element, having a given attribute equals a given value, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsByAttributeUntil('content', 'data-id', '42', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
value
- the value of the attribute.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsByClass
Gets the siblings of the element, having a given class name.
Usage example:
var items = o2.Dom.getSiblingsByClass('content', 'selected', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsByClassUntil
Gets the siblings of the element, having a given class name, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsByClassUntil('content', 'selected', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsUntil
Gets the siblings of the element until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsWithAttribute
Gets the siblings of the element, having a given attribute defined.
Usage example:
var items = o2.Dom.getSiblingsWithAttribute('content', 'dada-id', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsWithAttributeUntil
Gets the siblings of the element, having a given attribute defined, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsWithAttributeUntil('content', 'data-id', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
attribute
- the name of the attribute to filter.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsWithClass
Gets the siblings of the element, having "class" attribute defined.
Usage example:
var items = o2.Dom.getSiblingsWithClass('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsWithClassUntil
Gets the siblings of the element, having a "class" attribute defined, until (but not included to) a specific node.
Usage example:
var items = o2.Dom.getSiblingsWithClassUntil('content', 'stopper', 'li');
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsWithId
Gets the siblings of the element, having an "id" attribute defined.
Usage example:
var items = o2.Dom.getSiblingsWithId('content', 'li');
elm
- the element reference, or a String
id of it.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getSiblingsWithIdUntil
Usage example:
var items = o2.Dom.getSiblingsWithIdUntil('content', 'stopper', 'li');
Gets the siblings of the element, having an "id" attribute defined, until (but not included to) a specific node.
elm
- the element reference, or a String
id of it.
until
- the DOM to search until (but
not included to), or its String
id.
name
- (Optional; defaults to undefined
),
if true, only the results with that node name (i.e.
HTML Tag Name) are selected. Array
of nodes, if found; and empty
Array
if nothing is found.
function getStyle
Gets the style of a given property of the element.
Tries to parse the currentStyle
, if available;
otherwise tries to calculate the style using
window.getComputedStyle
;
gets obj.style
if everything else fails.
Note that adding and removing style attributes to a DOM not is considered "bad practice". Do not use inline styles to modify the view; assign className's instead of style values.
Usage example:
var color = o2.Dom.getStyle('container', 'color');
elm
- the element, or the id of it,
to check.
cssProperty
- the css property either
dash-separated
or camelCased (i.e.: 'border-color' or
'borderColor')
isNoForce
- (optional; defaults to
false
)
if true
inherited values from the CSS files will also be
parsed, otherwise, only inline styles will be parsed. function getText
static
getText(Object
elm)
Gets the textual content of the given node, replacing entities
like & amp;
with it's corresponding character
counterpart (& in this example).
Usage example:
var txt = o2.Dom.getText('container');
elm
- the DOM node or its
String
id. function getViewportInfo
static
getViewportInfo()
Gets the viewport information in the form
{scrollTop : #, scrollLeft: #, width: #, height: #}
.
Usage example:
var details = o2.Dom.getViewportInfo();
function getWidth
static
getWidth(Object
obj)
Gets the width of the given element, in pixels.
obj
- the DOMNode to get the dimension
of, or the String
id of it.
Usage example:
var elementWidth = o2.Dom.getWidth('container');
function getWindowInnerDimension
static
getWindowInnerDimension()
Gets the dimension of the visible area of the browser in the form
{width: w, height: h}
.
Usage example:
var windowDimensions = o2.Dom.getWindowInnerDimension();
{width: w, height: h}
.
function getWindowInnerHeight
static
getWindowInnerHeight()
Gets the inner height of the visible area.
Usage example:
var innerHeight = o2.Dom.getWindow.innerHeight();
function getWindowInnerWidth
static
getWindowInnerWidth()
Gets the inner width of the visible area.
Usage example:
var innerWidth = o2.Dom.getWindowInnerWidth();
function getWindowScrollOffset
static
getWindowScrollOffset()
Gets the window's scroll offset.
Usage example:
var offsets = o2.Dom.getWindowScrollOffset();
{left: l, top: t}
.
function hasClass
static
hasClass(DomNode
el, String
c)
Checks whether an element has the given className.
Usage example:
if (o2.Dom.hasClass('container', 'active')) { doStuff(); }
el
- either the element, or the
id of it.
c
- the className to test. true
if el has the
className
c, false
otherwise.
function hide
static
hide(Object
obj)
Hides the given object.
Usage example:
o2.Dom.hide('container');
obj
- the DOM node, or the
id to hide. function insertAfter
Adds the node after the reference node.
Usage example:
var ref = o2.$('ref'); var new = o2.$('new'); o2.Dom.insertAfter(new, ref);
elmNewNode
- the DOM node, or the id of
the node, to insert after.
elmRefNode
- the reference node, or the
id of the node. function insertBefore
Adds the node before the reference node.
Usage example:
var ref = o2.$('ref'); var new = o2.$('new'); o2.Dom.insertBefore(new, ref);
elmNewNode
- the node, or the id of the
node, to insert before.
elmRefNode
- the reference, or the id of
the node. function isChild
Checks whether elm is the child of ref.
Usage example:
var isChild = o2.Dom.isChild('child', 'parent');
elm
- the source element, or a String
id of it.
ref
- the reference element, or a String
id of it. true
if elm is a child of
ref; false
otherwise.
function isDocument
static
isDocument(DOMNode
obj)
Checks whether the given node is a document
node.
Usage example:
var isDocument = o2.Dom.isDocument(currentNode);
obj
- the node to test. true
if the node is the
document
element; false
otherwise.
function isElement
static
isElement(DOMNode
obj)
Checks whether the given node is an element node.
Usage example:
var isElement = o2.Dom.isElement(currentNode);
obj
- the node to test. true
if the node is an
element node; false
otherwise.
function isNext
Checks whether elm is a sibling after ref.
Usage example:
var isNext = o2.Dom.isNext('itemId', 'refId');
elm
- the source element, or a String
id of it.
ref
- the reference element, or a String
id of it. true
if elm is a sibling after
ref; false
otherwise.
function isParent
Checks whether elm is a parent of ref.
Usage example:
var isParent = o2.Dom.isParent('itemId', 'refId');
elm
- the source element, or a String
id of it.
ref
- the reference element, or a String
id of it. true
if elm is a parent of
ref; false
otherwise.
function isParentOrSelf
Checks whether elm is parent of ref, or it's the ref itself.
Usage example:
var isParent = o2.Dom.isParentOrSelf('itemId', 'refId');
elm
- the source element, or a String
id of it.
ref
- the reference element, or a String
id of it. true
if elm is a parent of
ref, or the node itself; false
otherwise.
function isPrev
Checks whether elm is a sibling before ref.
Usage example:
var isParent = o2.Dom.isPrev('itemId', 'refId');
elm
- the source element, or a String
id of it.
ref
- the reference element, or a String
id of it. true
if elm is a sibling before
ref; false
otherwise.
function isSibling
Checks whether elm is a sibling of ref.
Usage example:
var isSibling = o2.Dom.isSibling('itemId', 'refId');
elm
- the source element, or a String
id of it.
ref
- the reference element, or a String
id of it. true
if elm is a sibling of
ref; false
otherwise.
function isVisible
static
isVisible(Object
obj)
Checks whether the DOM node is visible.
Note that being visible does not necessarily mean being available inside the viewport.
If a DOM node has display == 'none'
or visibility == 'hidden'
CSS properties,
then it's regarded as "invisible", otherwise it is considered to be
"visible".
Usage example:
var isContainerVisible = o2.Dom.isVisible('container');
obj
- the DOM element, or the
id of it, to test. true
if the element is visible, false
otherwise.
function loadCss
static
loadCss(String
src, Function
successCallback)
Asynchronously loads a css file with a given src.
Cross-domain loading is also okay: The css file does not have to be in the same domain as the web page.
The success and failure callbacks is a somewhat hacky way of handling CSS load events. In deed, detecting CSS load is not an easy task, and it's not necessary most of the time.
Though it may get handy to prevent the Flash of Unstyled Content (FOUC) issues.
A more robust way of handling load callbacks is polling the property of a test element (such as the background color), that you know that the loaded CSS will change for sure.
Usage example:
o2.Dom.loadCss('http://cdn.example/com/theme.css', function() { handleSuccess(); });
src
- the source URL of the
css file.
successCallback
- the callback to execute when the load
operation completes. function loadImage
static
loadImage(String
url, Function
successCallback)
Tries to load the image into a JavaScript
Image
object; then triggers
successCallback
or failureCallback
depending on
the
result of the load attempt.
This function can be used for pre-loading or post-loading images.
Usage example:
o2.Dom.loadImage('http//asset.example.com/spinner.png', function() { handleSuccess(); });
url
- the URL of the
image.
successCallback
- gets called when the
image is loaded successfully. function loadScript
static
loadScript(String
src, Function
callback)
Asynchronously loads a script with a given src.
Cross-domain loading is also okay: The script does not have to be in the same domain as the web page.
Usage example:
o2.Dom.loadImage('http//asset.example.com/script.js', function() { handleSuccess(); });
src
- the source URL of the
script.
callback
- the callback to execute when the load
operation completes. function prepend
Prepends the element to the top of its parent.
Usage example:
var child = o2.$('ChildContainer'); var parent = o2.$('MasterContainer'); o2.Dom.prepend(child, parent);
elmChild
- the child node, or the id of the node to
prepend.
elmParent
- the parent container, or the id of the
container. function preventMultipleSubmit
static
preventMultipleSubmit(Object
form)
Prevents the form to re-submit itself when the submit button is pressed more than once.
Usage example:
o2.Dom.preventMultipleSubmit('actionForm');
form
- A DOM reference to the form
object or its String
id. function ready
static
ready(Function
delegate)
Fires when the HTML DOM
is ready.
Usage example:
o2.Dom.ready(function() { doInitializaton(); });
delegate
- the callback that's called when the DOM is
ready. function remove
static
remove(Object
e)
Removes the element from the DOM flow.
Usage example:
o2.Dom.remove('nagivation');
e
- either the element, or the
id of it, to remove. function removeChildren
static
removeChildren(Object
e)
Removes all the children of the element.
Usage example:
o2.Dom.removeChildren('container');
e
- either the element, or the
id of it to process. function removeClass
static
removeClass(DomNode
el, String
c)
Removes a class name from the given node.
Usage example:
o2.Dom.removeClass('container', 'active');
el
- either the element, or the
id of it.
c
- the className to remove. function removeEmpty
static
removeEmpty()
An alias to o2.Dom.removeEmptyTextNodes.
function removeEmptyTextNodes
static
removeEmptyTextNodes(Object
e)
Removes empty text nodes from the element.
Note that this removal is not recursive; only the first-level empty child nodes of the element will be removed.
Usage example:
o2.Dom.removeEmptyTextNodes('container');
e
- either the element, or the
id of it to process. function removeNode
static
removeNode()
An alias to o2.Dom.remove.
function replace
static
replace(
elmTarget,
elmToReplace)
Replaces one node with another.
Usage example:
o2.Dom.replace('firstContainer', 'secondContainer');
elmTarget
- the target node or its String
id.
elmToReplace
- the replacement node or its String
id. function scrollObjectToBottom
static
scrollObjectToBottom(Object
obj)
Scrolls an element to bottom.
Usage example:
o2.Dom.scrollObjectToBottom('container');
obj
- the element, or the id of it, to
scroll. function scrollObjectToTop
static
scrollObjectToTop(Object
obj)
Scrolls an element to top.
Usage example:
o2.Dom.scrollObjectToTop('container');
obj
- the element, or the id of the
element, to scroll. function scrollTo
static
scrollTo()
An alias to o2.Dom.scrollWindowToObject.
function scrollToObject
static
scrollToObject()
An alias to o2.Dom.scrollWindowToObject.
function scrollWindowToBottom
static
scrollWindowToBottom()
Usage example:
o2.Dom.scrollWindowToBottom();
Scrolls window to bottom.
function scrollWindowToObject
static
scrollWindowToObject()
An alias to o2.Dom.scrollWindowToObject.
function scrollWindowToTop
static
scrollWindowToTop()
Usage example:
o2.Dom.scrollWindowToTop();
Scrolls window to top.
function setAttribute
Sets the attribute of the given object.
Usage example:
o2.Dom.setAttribute('container', 'data-user-id', '123');
elm
- the object or the String
id of it.
attribute
- the name of the attribute.
value
- the value of the attribute. function setCss
static
setCss()
An alias to o2.Dom.addStyle.
function setDimension
Sets the dimension of the given element.
Usage example:
o2.Dom.setDimension('container', {width: 400, height: 200});
obj
- the DOMNode to get the dimension
of, or the String
id of it.
dimension
- the new dimension in the form
{width: w, height: h}
. function setHeight
static
setHeight(Object
obj, Integer
height)
Sets the height of the given element.
Usage example:
o2.Dom.setHeight('container', 300);
obj
- the DOMNode to get the dimension
of, or the String
id of it.
height
- the new height in pixels. function setHtml
static
setHtml(Object
elm)
Simply sets the innerHTML
of the element.
Usage example:
o2.Dom.setHtml('container', '[h1]hello[/h1]');
elm
- The DOM element to set the
HTML of, or its String
id. function setStyle
static
setStyle()
An alias to o2.Dom.addStyle.
function setWidth
static
setWidth(Object
obj, Integer
width)
Sets the width of the given element.
Usage example:
o2.Dom.setWidth('container', 500);
obj
- the DOMNode to get the dimension
of, or the String
id of it.
width
- the new width in pixels. function show
static
show(Object
elm)
Shows the given object.
Usage example:
o2.Dom.show('container');
elm
- the DOM node, or the
id of it, to show. function toggleClass
Toggles the CSS className
of a given
element.
Usage example:
o2.Dom.toggleClass('container', 'active');
el
- the DOM element to toggle or its
String
id.
c
- the class name to toggle.
state
- (Optional, defaults to undefined
),
if true
add class c to
el, if true
removes class
c from el. If the parameter is not
given, the class is toggled (i.e. added if the class does not exist,
and removed if the class exists). function toggleVisibility
static
toggleVisibility(Object
elm, Boolean
state)
Toggles the visibility of the given element.
Usage example:
o2.Dom.toggleVisibility('container');
elm
- a DOM reference or its
String
id.
state
- (Optional, defaults to undefined
)
if true
, show the item; if false
hides the
item; if undefined
simply toggles the visibility of the
item. function trimField
static
trimField(Object
field)
Trims a given field, and returns the trimmed value.
Usage example:
o2.Dom.trimField('txtInput');
field
- the field to be trimmed, or its
id. null
if the field
does not exist.
function unwrap
static
unwrap(Object
elmTarget)
This is like o2.Dom.wrap in reverse.
Moves all the elements inside the container to the container's position and removes the container from the DOM.
Usage example:
o2.Dom.unwrap('container');
elmTarget
- the target node or its String
id
to unwrap. function wrap
Puts the target element into the wrapper element.
Usage example:
var wrapper = o2.$('wrapper'); var target = o2.$('content'); o2.Dom.wrap(target, wrapper);
elmTarget
- the node to wrap or its String
id.
elmWrapper
- the wrapper node ot its String
id.