dom.DomHelper Extends Object
Create an instance of a DOM helper with a new document object.

Inheritance

Constructor

goog.dom.DomHelper(opt_document)

Parameters

opt_document :
(Document | null | undefined)
Document object to associate with this DOM helper.

Instance Methods

Public Protected Private
$(element)
(Element | null)
Use goog.dom.DomHelper.prototype.getElement instead. Alias for getElement.
Arguments:
element :
(Element | null | string)
Element ID or a DOM node.
Returns: 
(Element | null)
  The element with the given ID, or the node passed in.
code »
$$(opt_tagopt_classopt_el)
{length: number}
Use DomHelper getElementsByTagNameAndClass. Alias for getElementsByTagNameAndClass.
Arguments:
opt_tag :
(null | string | undefined)
Element tag name.
opt_class :
(null | string | undefined)
Optional class name.
opt_el :
(Element | null | undefined)
Optional element to look in.
Returns: 
{length: number}
  Array-like list of elements (only a length property and numerical indices are guaranteed to exist).
code »
$dom(tagNameopt_attributesvar_args)
Use goog.dom.DomHelper.prototype.createDom instead. Alias for createDom.
Arguments:
tagName :
Tag to create.
opt_attributes :
(Object | null | string | undefined)
If object, then a map of name-value pairs for attributes. If a string, then this is the className of the new element.
var_args :
(Object | null | string | undefined)
Further DOM nodes or strings for text nodes. If one of the var_args is an array, its children will be added as childNodes instead.
Returns:   Reference to a DOM node.
code »
append(parentvar_args)
Appends a node with text or other nodes.
Arguments:
parent :
The node to append nodes to.
var_args :
(Object | null | string | undefined)
The things to append to the node. If this is a Node it is appended as is. If this is a string then a text node is appended. If this is an array like object then fields 0 to length - 1 are appended.
code »
appendChild(parentchild)
Appends a child to a node.
Arguments:
parent :
(Node | null)
Parent.
child :
(Node | null)
Child.
code »
contains(parentdescendant)
Whether a node contains another node.
Arguments:
parent :
(Node | null)
The node that should contain the other node.
descendant :
(Node | null)
The node to test presence of.
Returns:   Whether the parent node contains the descendent node.
code »
createDom(tagNameopt_attributesvar_args)
Returns a dom node with a set of attributes. This function accepts varargs for subsequent nodes to be added. Subsequent nodes will be added to the first node as childNodes. So: createDom('div', null, createDom('p'), createDom('p')); would return a div with two child paragraphs An easy way to move all child nodes of an existing element to a new parent element is: createDom('div', null, oldElement.childNodes); which will remove all child nodes from the old element and add them as child nodes of the new DIV.
Arguments:
tagName :
Tag to create.
opt_attributes :
(Object | null | string | undefined)
If object, then a map of name-value pairs for attributes. If a string, then this is the className of the new element.
var_args :
(Object | null | string | undefined)
Further DOM nodes or strings for text nodes. If one of the var_args is an array or NodeList, its elements will be added as childNodes instead.
Returns:   Reference to a DOM node.
code »
createElement(name)
Creates a new element.
Arguments:
name :
Tag name.
Returns:   The new element.
code »
createTable(rowscolumnsopt_fillWithNbsp)
Create a table.
Arguments:
rows :
The number of rows in the table. Must be >= 1.
columns :
The number of columns in the table. Must be >= 1.
opt_fillWithNbsp :
(boolean | undefined)
If true, fills table entries with nsbps.
Returns:   The created table.
code »
createTextNode(content)
Text
Creates a new text node.
Arguments:
content :
Content.
Returns: 
Text
  The new text node.
code »
findNode(rootp)
(Node | null | undefined)
Finds the first descendant node that matches the filter function. This does a depth first search.
Arguments:
root :
(Node | null)
The root of the tree to search.
p :
function ((Node | null)): boolean
The filter function.
Returns: 
(Node | null | undefined)
  The found node or undefined if none is found.
code »
findNodes(rootp)
(Array | null)
Finds all the descendant nodes that matches the filter function. This does a depth first search.
Arguments:
root :
(Node | null)
The root of the tree to search.
p :
function ((Node | null)): boolean
The filter function.
Returns: 
(Array | null)
  The found nodes or an empty array if none are found.
code »
flattenElement(element)
(Element | null | undefined)
Flattens an element. That is, removes it and replace it with its children.
Arguments:
element :
(Element | null)
The element to flatten.
Returns: 
(Element | null | undefined)
  The original element, detached from the document tree, sans children, or undefined if the element was already not in the document.
code »
getAncestor(elementmatcheropt_includeNodeopt_maxSearchSteps)
(Node | null)
Walks up the DOM hierarchy returning the first ancestor that passes the matcher function.
Arguments:
element :
(Node | null)
The DOM node to start with.
matcher :
function ((Node | null)): boolean
A function that returns true if the passed node matches the desired criteria.
opt_includeNode :
(boolean | undefined)
If true, the node itself is included in the search (the first call to the matcher will pass startElement as the node to test).
opt_maxSearchSteps :
(number | undefined)
Maximum number of levels to search up the dom.
Returns: 
(Node | null)
  DOM node that matched the matcher, or null if there was no match.
code »
getAncestorByClass(elementopt_class)
(Node | null)
Walks up the DOM hierarchy returning the first ancestor that has the passed class name. If the passed element matches the specified criteria, the element itself is returned.
Arguments:
element :
(Node | null)
The DOM node to start with.
opt_class :
(null | string | undefined)
The class name to match (or null/undefined to match any node regardless of class name).
Returns: 
(Node | null)
  The first ancestor that matches the passed criteria, or null if none match.
code »
getAncestorByTagNameAndClass(elementopt_tagopt_class)
(Node | null)
Walks up the DOM hierarchy returning the first ancestor that has the passed tag name and/or class name. If the passed element matches the specified criteria, the element itself is returned.
Arguments:
element :
(Node | null)
The DOM node to start with.
opt_tag :
(null | string | undefined)
The tag name to match (or null/undefined to match any node regardless of tag name). Must be uppercase (goog.dom.TagName).
opt_class :
(null | string | undefined)
The class name to match (or null/undefined to match any node regardless of class name).
Returns: 
(Node | null)
  The first ancestor that matches the passed criteria, or null if none match.
code »
getCompatMode()
use goog.dom.DomHelper.prototype.isCss1CompatMode instead. Returns the compatMode of the document.
Returns:   The result is either CSS1Compat or BackCompat.
code »
getDocument()
Gets the document object being used by the dom library.
Returns:   Document object.
code »
getDocumentHeight()
Calculates the height of the document.
Returns:   The height of the document.
code »
getDocumentScroll()
Gets the document scroll distance as a coordinate object.
Returns:   Object with properties 'x' and 'y'.
code »
getDocumentScrollElement()
(Element | null)
Gets the document scroll element.
Returns: 
(Element | null)
  Scrolling element.
code »
getDomHelper(opt_node)
Gets the dom helper object for the document where the element resides.
Arguments:
opt_node :
(Node | null | undefined)
If present, gets the DomHelper for this node.
Returns:   The DomHelper.
code »
getElement(element)
(Element | null)
Alias for getElementById. If a DOM node is passed in then we just return that.
Arguments:
element :
(Element | null | string)
Element ID or a DOM node.
Returns: 
(Element | null)
  The element with the given ID, or the node passed in.
code »
getElementByClass(classNameopt_el)
(Element | null)
Returns the first element we find matching the provided class name.
Arguments:
className :
the name of the class to look for.
opt_el :
(Document | Element | null | undefined)
Optional element to look in.
Returns: 
(Element | null)
  The first item found with the class name provided.
code »
getElementsByClass(classNameopt_el)
{length: number}
Returns an array of all the elements with the provided className.
Arguments:
className :
the name of the class to look for.
opt_el :
(Document | Element | null | undefined)
Optional element to look in.
Returns: 
{length: number}
  The items found with the class name provided.
code »
getElementsByTagNameAndClass(opt_tagopt_classopt_el)
{length: number}
Looks up elements by both tag and class name, using browser native functions (querySelectorAll, getElementsByTagName or getElementsByClassName) where possible. The returned array is a live NodeList or a static list depending on the code path taken.
Arguments:
opt_tag :
(null | string | undefined)
Element tag name or * for all tags.
opt_class :
(null | string | undefined)
Optional class name.
opt_el :
(Document | Element | null | undefined)
Optional element to look in.
Returns: 
{length: number}
  Array-like list of elements (only a length property and numerical indices are guaranteed to exist).
code »
getFirstElementChild(node)
(Element | null)
Returns the first child node that is an element.
Arguments:
node :
(Node | null)
The node to get the first child element of.
Returns: 
(Element | null)
  The first child node of node that is an element.
code »
getFrameContentDocument(iframe)
HTMLDocument
Cross browser function for getting the document element of an iframe.
Arguments:
iframe :
(HTMLFrameElement | HTMLIFrameElement | null)
Iframe element.
Returns: 
HTMLDocument
  The frame content document.
code »
getFrameContentWindow(frame)
(Window | null)
Cross browser function for getting the window of a frame or iframe.
Arguments:
frame :
(HTMLFrameElement | HTMLIFrameElement | null)
Frame element.
Returns: 
(Window | null)
  The window associated with the given frame.
code »
getLastElementChild(node)
(Element | null)
Returns the last child node that is an element.
Arguments:
node :
(Node | null)
The node to get the last child element of.
Returns: 
(Element | null)
  The last child node of node that is an element.
code »
getNextElementSibling(node)
(Element | null)
Returns the first next sibling that is an element.
Arguments:
node :
(Node | null)
The node to get the next sibling element of.
Returns: 
(Element | null)
  The next sibling of node that is an element.
code »
getNextNode(node)
(Node | null)
Returns the next node in source order from the given node.
Arguments:
node :
(Node | null)
The node.
Returns: 
(Node | null)
  The next node in the DOM tree, or null if this was the last node.
code »
getNodeTextLength(node)
Returns the text length of the text contained in a node, without markup. This is equivalent to the selection length if the node was selected, or the number of cursor movements to traverse the node. Images & BRs take one space. New lines are ignored.
Arguments:
node :
(Node | null)
The node whose text content length is being calculated.
Returns:   The length of node's text content.
code »
getNodeTextOffset(nodeopt_offsetParent)
Returns the text offset of a node relative to one of its ancestors. The text length is the same as the length calculated by goog.dom.getNodeTextLength.
Arguments:
node :
(Node | null)
The node whose offset is being calculated.
opt_offsetParent :
(Node | null | undefined)
Defaults to the node's owner document's body.
Returns:   The text offset.
code »
getOwnerDocument(node)
Returns the owner document for a node.
Arguments:
node :
(Node | null)
The node to get the document for.
Returns:   The document owning the node.
code »
getPreviousElementSibling(node)
(Element | null)
Returns the first previous sibling that is an element.
Arguments:
node :
(Node | null)
The node to get the previous sibling element of.
Returns: 
(Element | null)
  The first previous sibling of node that is an element.
code »
getPreviousNode(node)
(Node | null)
Returns the previous node in source order from the given node.
Arguments:
node :
(Node | null)
The node.
Returns: 
(Node | null)
  The previous node in the DOM tree, or null if this was the first node.
code »
getTextContent(node)
Returns the text contents of the current node, without markup. New lines are stripped and whitespace is collapsed, such that each character would be visible. In browsers that support it, innerText is used. Other browsers attempt to simulate it via node traversal. Line breaks are canonicalized in IE.
Arguments:
node :
(Node | null)
The node from which we are getting content.
Returns:   The text content.
code »
getViewportSize(opt_window)
Gets the dimensions of the viewport.
Arguments:
opt_window :
(Window | null | undefined)
Optional window element to test. Defaults to the window of the Dom Helper.
Returns:   Object with values 'width' and 'height'.
code »
getWindow()
Gets the window object associated with the document.
Returns:   The window associated with the given document.
code »
htmlToDocumentFragment(htmlString)
Converts an HTML string into a node or a document fragment. A single Node is used if the htmlString only generates a single node. If the htmlString generates multiple nodes then these are put inside a DocumentFragment.
Arguments:
htmlString :
The HTML string to convert.
Returns:   The resulting node.
code »
insertSiblingAfter(newNoderefNode)
Inserts a new node after an existing reference node (i.e., as the next sibling). If the reference node has no parent, then does nothing.
Arguments:
newNode :
(Node | null)
Node to insert.
refNode :
(Node | null)
Reference node to insert after.
code »
insertSiblingBefore(newNoderefNode)
Inserts a new node before an existing reference node (i.e., as the previous sibling). If the reference node has no parent, then does nothing.
Arguments:
newNode :
(Node | null)
Node to insert.
refNode :
(Node | null)
Reference node to insert before.
code »
isCss1CompatMode()
Returns true if the browser is in "CSS1-compatible" (standards-compliant) mode, false otherwise.
Returns:   True if in CSS1-compatible mode.
code »
isNodeLike(obj)
Whether the object looks like a DOM node.
Arguments:
obj :
*
The object being tested for node likeness.
Returns:   Whether the object looks like a DOM node.
code »
removeChildren(node)
Removes all the child nodes on a DOM node.
Arguments:
node :
(Node | null)
Node to remove children from.
code »
removeNode(node)
(Node | null)
Removes a node from its parent.
Arguments:
node :
(Node | null)
The node to remove.
Returns: 
(Node | null)
  The node removed if removed; else, null.
code »
replaceNode(newNodeoldNode)
Replaces a node in the DOM tree. Will do nothing if oldNode has no parent.
Arguments:
newNode :
(Node | null)
Node to insert.
oldNode :
(Node | null)
Node to replace.
code »
setDocument(document)
Sets the document object.
Arguments:
document :
Document object.
code »
setProperties(elementproperties)
Sets a number of properties on a node.
Arguments:
element :
(Element | null)
DOM node to set properties on.
properties :
(Object | null)
Hash of property:value pairs.
code »
setTextContent(elementtext)
Cross browser function for setting the text content of an element.
Arguments:
element :
(Element | null)
The element to change the text content of.
text :
The string that should replace the current element content with.
code »

Instance Properties

document_ :
Reference to the document object to use
Code »

Package dom

Package Reference