DOM Class
+ + + + +Provides DOM helper methods.
+Item Index
+ + +Methods
+ +-
+
+
- + _bruteContains + + + + + +
- + _getDoc + + + + + +
- + _getRegExp + + + + + +
- + _getWin + + + + + +
- + addClass + + + + + +
- + addHTML + + + + + +
- + byId + + + + + +
- + contains + + + + + +
- + create + + + + + +
- + docHeight + + + + + +
- + docScrollX + + + + + +
- + docScrollY + + + + + +
- + docWidth + + + + + +
- + elementByAxis + + + + + +
- + getAttribute + + + + + +
- + getComputedStyle + + + + + +
- + getScrollbarWidth + + + + + +
- + getStyle + + + + + +
- + getText + + + + + +
- + getX + + + + + +
- + getXY + + + + + +
- + getY + + + + + +
- + hasClass + + + + + +
- + inDoc + + + + + +
- + inRegion + + + + + +
- + intersect + + + + + +
- + inViewportRegion + + + + + +
- + region + + + + + +
- + removeClass + + + + + +
- + replaceClass + + + + + +
- + setAttribute + + + + + +
- + setHeight + + + + + +
- + setStyle + + + + + +
- + setStyles + + + + + +
- + setText + + + + + +
- + setWidth + + + + + +
- + setX + + + + + +
- + setXY + + + + + +
- + setY + + + + + +
- + swapXY + + + + + +
- + toggleClass + + + + + +
- + viewportRegion + + + + + +
- + winHeight + + + + + +
- + winWidth + + + + + +
Methods
+ + +_bruteContains
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
needle+ +
+
+
Brute force version of contains. +Used for browsers without contains support for non-HTMLElement Nodes (textNodes, etc).
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The containing html element.
+
+
+ -
+
+
needle+ HTMLElement + + + + +++ + +The html element that may be contained.
+
+
+
Returns:
+ +_getDoc
+
+
+ -
+
+
-
+
+
element+ +
+
+
returns the appropriate document.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +optional Target element.
+
+
+
Returns:
+ +_getRegExp
+
+
+ -
+
+
-
+
+
str+ +
+
+ -
+
+
flags+ +
+
+
Memoizes dynamic regular expressions to boost runtime performance.
+Parameters:
+ + +Returns:
+ +_getWin
+
+
+ -
+
+
-
+
+
element+ +
+
+
returns the appropriate window.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +optional Target element.
+
+
+
Returns:
+ +addClass
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
className+ +
+
+
Adds a class name to a given DOM element.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element.
+
+
+ -
+
+
className+ String + + + + +++ + +the class name to add to the class attribute
+
+
+
addHTML
+
+
+ -
+
+
-
+
+
node+ +
+
+ -
+
+
content+ +
+
+ -
+
+
where+ +
+
+
Inserts content in a node at the given location
+Parameters:
+ +-
+
+
-
+
+
node+ HTMLElement + + + + +++ + +The node to insert into
+
+
+ -
+
+
content+ HTMLElement | Array | HTMLCollection + + + + +++ + +The content to be inserted
+
+
+ -
+
+
where+ HTMLElement + + + + +++ + +Where to insert the content +If no "where" is given, content is appended to the node +Possible values for "where"
+ +-
+
- HTMLElement +
- The element to insert before +
- "replace" +
- Replaces the existing HTML +
- "before" +
- Inserts before the existing HTML +
- "before" +
- Inserts content before the node +
- "after" +
- Inserts content after the node +
+
+
byId
+
+
+ -
+
+
-
+
+
id+ +
+
+ -
+
+
doc+ +
+
+
Returns the HTMLElement with the given ID (Wrapper for document.getElementById).
+Parameters:
+ + +Returns:
+ +contains
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
needle+ +
+
+
Determines whether or not one HTMLElement is or contains another HTMLElement.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The containing html element.
+
+
+ -
+
+
needle+ HTMLElement + + + + +++ + +The html element that may be contained.
+
+
+
Returns:
+ +create
+
+
+ -
+
+
-
+
+
html+ +
+
+ -
+
+
doc+ +
+
+
Creates a new dom node using the provided markup string.
+Parameters:
+ +-
+
+
-
+
+
html+ String + + + + +++ + +The markup used to create the element
+
+
+ -
+
+
doc+ HTMLDocument + + + + +++ + +An optional document context
+
+
+
Returns:
+ +docHeight
+
+
+ ()
+
+
+
+
+ Number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Document height
+Returns:
+ +docScrollX
+
+
+ ()
+
+
+
+
+ Number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Amount page has been scroll horizontally
+Returns:
+ +docScrollY
+
+
+ ()
+
+
+
+
+ Number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Amount page has been scroll vertically
+Returns:
+ +docWidth
+
+
+ ()
+
+
+
+
+ Number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Document width
+Returns:
+ +elementByAxis
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
axis+ +
+
+ -
+
+
fn+ +
+
+ -
+
+
all+ +
+
+
Searches the element by the given axis for the first matching element.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The html element.
+
+
+ -
+
+
axis+ String + + + + +++ + +The axis to search (parentNode, nextSibling, previousSibling).
+
+
+ -
+
+
fn+ Function + + + + +++ + +optional An optional boolean test to apply.
+
+
+ -
+
+
all+ Boolean + + + + +++ + +optional Whether all node types should be returned, or just element nodes. +The optional function is passed the current HTMLElement being tested as its only argument. +If no function is given, the first element is returned.
+
+
+
Returns:
+ +getAttribute
+
+
+ -
+
+
-
+
+
el+ +
+
+ -
+
+
attr+ +
+
+
Provides a normalized attribute interface.
+Parameters:
+ +-
+
+
-
+
+
el+ HTMLElement + + + + +++ + +The target element for the attribute.
+
+
+ -
+
+
attr+ String + + + + +++ + +The attribute to get.
+
+
+
Returns:
+ +getComputedStyle
+
+
+ -
+
+
-
+
+
An+ +
+
+ -
+
+
att+ +
+
+
Returns the computed style for the given node.
+Parameters:
+ +-
+
+
-
+
+
An+ HTMLElement + + + + +++ + +HTMLElement to get the style from.
+
+
+ -
+
+
att+ String + + + + +++ + +The style property to get.
+
+
+
Returns:
+ +getScrollbarWidth
+
+
+ ()
+
+
+
+
+ Number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Gets the width of vertical scrollbars on overflowed containers in the body +content.
+Returns:
+ +getStyle
+
+
+ -
+
+
-
+
+
An+ +
+
+ -
+
+
att+ +
+
+
Returns the current style value for the given property.
+Parameters:
+ +-
+
+
-
+
+
An+ HTMLElement + + + + +++ + +HTMLElement to get the style from.
+
+
+ -
+
+
att+ String + + + + +++ + +The style property to get.
+
+
+
getText
+
+
+ -
+
+
-
+
+
element+ +
+
+
Returns the text content of the HTMLElement.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The html element.
+
+
+
Returns:
+ +getX
+
+
+ -
+
+
-
+
+
element+ +
+
+
Gets the current X position of an element based on page coordinates. +Element must be part of the DOM tree to have page coordinates +(display:none or elements not appended return false).
+Parameters:
+ +-
+
+
-
+
+
element+ Object + + + + +++ + +The target element
+
+
+
Returns:
+ +getXY
+
+
+ -
+
+
-
+
+
element+ +
+
+
Gets the current position of an element based on page coordinates. +Element must be part of the DOM tree to have page coordinates +(display:none or elements not appended return false).
+Parameters:
+ +-
+
+
-
+
+
element+ Object + + + + +++ + +The target element
+
+
+
Returns:
+ +TODO: test inDocument/display?
+
+
+ getY
+
+
+ -
+
+
-
+
+
element+ +
+
+
Gets the current Y position of an element based on page coordinates. +Element must be part of the DOM tree to have page coordinates +(display:none or elements not appended return false).
+Parameters:
+ +-
+
+
-
+
+
element+ Object + + + + +++ + +The target element
+
+
+
Returns:
+ +hasClass
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
className+ +
+
+
Determines whether a DOM element has the given className.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element.
+
+
+ -
+
+
className+ String + + + + +++ + +the class name to search for
+
+
+
Returns:
+ +inDoc
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
doc+ +
+
+
Determines whether or not the HTMLElement is part of the document.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The containing html element.
+
+
+ -
+
+
doc+ HTMLElement + + + + +++ + +optional The document to check.
+
+
+
Returns:
+ +inRegion
+
+
+ -
+
+
-
+
+
node+ +
+
+ -
+
+
node2+ +
+
+ -
+
+
all+ +
+
+ -
+
+
altRegion+ +
+
+
Check if any part of this node is in the passed region
+Parameters:
+ +-
+
+
-
+
+
node+ Object + + + + +++ + +The node to get the region from
+
+
+ -
+
+
node2+ Object + + + + +++ + +The second node to get the region from or an Object literal of the region
+
+
+ -
+
+
all+ Boolean + + + + +++ + +Should all of the node be inside the region
+
+
+ -
+
+
altRegion+ Object + + + + +++ + +An object literal containing the region for this node if we already have the data (for performance e.g. DragDrop)
+
+
+
Returns:
+ +intersect
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
element2+ +
+
+ -
+
+
altRegion+ +
+
+
Find the intersect information for the passed nodes.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The first element
+
+
+ -
+
+
element2+ HTMLElement | Object + + + + +++ + +The element or region to check the interect with
+
+
+ -
+
+
altRegion+ Object + + + + +++ + +An object literal containing the region for the first element if we already have the data (for performance e.g. DragDrop)
+
+
+
Returns:
+ +inViewportRegion
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
all+ +
+
+ -
+
+
altRegion+ +
+
+
Check if any part of this element is in the viewport
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element.
+
+
+ -
+
+
all+ Boolean + + + + +++ + +Should all of the node be inside the region
+
+
+ -
+
+
altRegion+ Object + + + + +++ + +An object literal containing the region for this node if we already have the data (for performance e.g. DragDrop)
+
+
+
Returns:
+ +region
+
+
+ -
+
+
-
+
+
element+ +
+
+
Returns an Object literal containing the following about this element: (top, right, bottom, left)
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element.
+
+
+
Returns:
+ +removeClass
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
className+ +
+
+
Removes a class name from a given element.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element.
+
+
+ -
+
+
className+ String + + + + +++ + +the class name to remove from the class attribute
+
+
+
replaceClass
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
oldClassName+ +
+
+ -
+
+
newClassName+ +
+
+
Replace a class with another class for a given element. +If no oldClassName is present, the newClassName is simply added.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element
+
+
+ -
+
+
oldClassName+ String + + + + +++ + +the class name to be replaced
+
+
+ -
+
+
newClassName+ String + + + + +++ + +the class name that will be replacing the old class name
+
+
+
setAttribute
+
+
+ -
+
+
-
+
+
el+ +
+
+ -
+
+
attr+ +
+
+ -
+
+
val+ +
+
+
Provides a normalized attribute interface.
+Parameters:
+ +-
+
+
-
+
+
el+ HTMLElement + + + + +++ + +The target element for the attribute.
+
+
+ -
+
+
attr+ String + + + + +++ + +The attribute to set.
+
+
+ -
+
+
val+ String + + + + +++ + +The value of the attribute.
+
+
+
setHeight
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
size+ +
+
+
Sets the height of the element to the given size, regardless +of box model, border, padding, etc.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element.
+
+
+ -
+
+
size+ String | Number + + + + +++ + +The pixel height to size to
+
+
+
setStyle
+
+
+ -
+
+
-
+
+
An+ +
+
+ -
+
+
att+ +
+
+ -
+
+
val+ +
+
+
Sets a style property for a given element.
+Parameters:
+ +-
+
+
-
+
+
An+ HTMLElement + + + + +++ + +HTMLElement to apply the style to.
+
+
+ -
+
+
att+ String + + + + +++ + +The style property to set.
+
+
+ -
+
+
val+ String | Number + + + + +++ + +The value.
+
+
+
setStyles
+
+
+ -
+
+
-
+
+
node+ +
+
+ -
+
+
hash+ +
+
+
Sets multiple style properties.
+Parameters:
+ +-
+
+
-
+
+
node+ HTMLElement + + + + +++ + +An HTMLElement to apply the styles to.
+
+
+ -
+
+
hash+ Object + + + + +++ + +An object literal of property:value pairs.
+
+
+
setText
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
content+ +
+
+
Sets the text content of the HTMLElement.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The html element.
+
+
+ -
+
+
content+ String + + + + +++ + +The content to add.
+
+
+
setWidth
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
size+ +
+
+
Sets the width of the element to the given size, regardless +of box model, border, padding, etc.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element.
+
+
+ -
+
+
size+ String | Number + + + + +++ + +The pixel height to size to
+
+
+
setX
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
x+ +
+
+
Set the X position of an html element in page coordinates, regardless of how the element is positioned. +The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
+setXY
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
xy+ +
+
+ -
+
+
noRetry+ +
+
+
Set the position of an html element in page coordinates. +The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
+Parameters:
+ + +setY
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
y+ +
+
+
Set the Y position of an html element in page coordinates, regardless of how the element is positioned. +The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
+swapXY
+
+
+ -
+
+
-
+
+
node+ +
+
+ -
+
+
otherNode+ +
+
+
Swap the xy position with another node
+Parameters:
+ + +Returns:
+ +toggleClass
+
+
+ -
+
+
-
+
+
element+ +
+
+ -
+
+
className+ +
+
+ -
+
+
addClass+ +
+
+
If the className exists on the node it is removed, if it doesn't exist it is added.
+Parameters:
+ +-
+
+
-
+
+
element+ HTMLElement + + + + +++ + +The DOM element
+
+
+ -
+
+
className+ String + + + + +++ + +the class name to be toggled
+
+
+ -
+
+
addClass+ Boolean + + + + +++ + +optional boolean to indicate whether class +should be added or removed regardless of current state
+
+
+
viewportRegion
+
+
+ ()
+
+
+
+
+ Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns an Object literal containing the following about the visible region of viewport: (top, right, bottom, left)
+