dom.js
Utilities for manipulating the browser's Document Object Model Inspiration taken *heavily* from mochikit (http://mochikit.com/). You can use goog.dom.DomHelper to create new dom helpers that refer to a different document object. This is useful if you are working with frames or multiple windows.

File Location

dom/dom.js

Classes

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

Public Protected Private

Global Functions

goog.dom.$()
Alias for getElement.
Returns:   The element with the given ID, or the node passed in.
code »
goog.dom.$$()
{length: number}
Alias for getElementsByTagNameAndClass.
Returns: 
{length: number}
  Array-like list of elements (only a length property and numerical indices are guaranteed to exist).
code »
goog.dom.$dom()
Alias for createDom.
Returns:   Reference to a DOM node.
code »
goog.dom.appendChild(appendChild@parentappendChild@child)
Appends a child to a node.
Arguments:
appendChild@parent :
No description.
appendChild@child :
No description.
code »
goog.dom.canHaveChildren(canHaveChildren@node)
Determines if the given node can contain children.
Arguments:
canHaveChildren@node :
No description.
Returns:   Whether the node can contain children.
code »
goog.dom.compareNodeOrder(compareNodeOrder@node1compareNodeOrder@node2)
Compares the document order of two nodes, returning 0 if they are the same node, a negative number if node1 is before node2, and a positive number if node2 is before node1. Note that we compare the order the tags appear in the document so in the tree text the B node is considered to be before the I node.
Arguments:
compareNodeOrder@node1 :
No description.
compareNodeOrder@node2 :
No description.
Returns:   0 if the nodes are the same node, a negative number if node1 is before node2, and a positive number if node2 is before node1.
code »
goog.dom.compareParentsDescendantNodeIe_(compareParentsDescendantNodeIe_@textNodecompareParentsDescendantNodeIe_@node)
Utility function to compare the position of two nodes, when textNode's parent is an ancestor of node. If this entry condition is not met, this function will attempt to reference a null object.
Arguments:
compareParentsDescendantNodeIe_@textNode :
No description.
compareParentsDescendantNodeIe_@node :
No description.
Returns:   -1 if node is before textNode, +1 otherwise.
code »
goog.dom.compareSiblingOrder_(compareSiblingOrder_@node1compareSiblingOrder_@node2)
Utility function to compare the position of two nodes known to be non-equal siblings.
Arguments:
compareSiblingOrder_@node1 :
No description.
compareSiblingOrder_@node2 :
No description.
Returns:   -1 if node1 is before node2, +1 otherwise.
code »
goog.dom.contains(contains@parentcontains@descendant)
Whether a node contains another node.
Arguments:
contains@parent :
No description.
contains@descendant :
No description.
Returns:   Whether the parent node contains the descendent node.
code »
goog.dom.createDom(createDom@tagNamecreateDom@opt_attributescreateDom@var_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
Arguments:
createDom@tagName :
No description.
createDom@opt_attributes :
No description.
createDom@var_args :
No description.
Returns:   Reference to a DOM node.
code »
goog.dom.createDom_(createDom_@doccreateDom_@args)
Helper for createDom.
Arguments:
createDom_@doc :
No description.
createDom_@args :
No description.
Returns:   Reference to a DOM node.
code »
goog.dom.createElement(createElement@name)
Creates a new element.
Arguments:
createElement@name :
No description.
Returns:   The new element.
code »
goog.dom.createTextNode(createTextNode@content)
!Text
Creates a new text node.
Arguments:
createTextNode@content :
No description.
Returns: 
!Text
  The new text node.
code »
goog.dom.findCommonAncestor(findCommonAncestor@var_args)
Find the deepest common ancestor of the given nodes.
Arguments:
findCommonAncestor@var_args :
No description.
Returns:   The common ancestor of the nodes, or null if there is none. null will only be returned if two or more of the nodes are from different documents.
code »
goog.dom.findNode(findNode@rootfindNode@p)
Node | undefined
Finds the first descendant node that matches the filter function, using a depth first search. This function offers the most general purpose way of finding a matching element. You may also wish to consider goog.dom.query which can express many matching criteria using CSS selector expressions. These expressions often result in a more compact representation of the desired result.
Arguments:
findNode@root :
No description.
findNode@p :
No description.
Returns: 
Node | undefined
  The found node or undefined if none is found.
code »
goog.dom.findNodes(findNodes@rootfindNodes@p)
Finds all the descendant nodes that match the filter function, using a a depth first search. This function offers the most general-purpose way of finding a set of matching elements. You may also wish to consider goog.dom.query which can express many matching criteria using CSS selector expressions. These expressions often result in a more compact representation of the desired result.
Arguments:
findNodes@root :
No description.
findNodes@p :
No description.
Returns:   The found nodes or an empty array if none are found.
code »
goog.dom.findNodes_(findNodes_@rootfindNodes_@pfindNodes_@rvfindNodes_@findOne)
Finds the first or all the descendant nodes that match the filter function, using a depth first search.
Arguments:
findNodes_@root :
No description.
findNodes_@p :
No description.
findNodes_@rv :
No description.
findNodes_@findOne :
No description.
Returns:   Whether the search is complete or not. True in case findOne is true and the node is found. False otherwise.
code »
goog.dom.flattenElement(flattenElement@element)
Element | undefined
Flattens an element. That is, removes it and replace it with its children. Does nothing if the element is not in the document.
Arguments:
flattenElement@element :
No description.
Returns: 
Element | undefined
  The original element, detached from the document tree, sans children; or undefined, if the element was not in the document to begin with.
code »
goog.dom.getAncestor(getAncestor@elementgetAncestor@matchergetAncestor@opt_includeNodegetAncestor@opt_maxSearchSteps)
Walks up the DOM hierarchy returning the first ancestor that passes the matcher function.
Arguments:
getAncestor@element :
No description.
getAncestor@matcher :
No description.
getAncestor@opt_includeNode :
No description.
getAncestor@opt_maxSearchSteps :
No description.
Returns:   DOM node that matched the matcher, or null if there was no match.
code »
goog.dom.getAncestorByTagNameAndClass(getAncestorByTagNameAndClass@elementgetAncestorByTagNameAndClass@opt_taggetAncestorByTagNameAndClass@opt_class)
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:
getAncestorByTagNameAndClass@element :
No description.
getAncestorByTagNameAndClass@opt_tag :
No description.
getAncestorByTagNameAndClass@opt_class :
No description.
Returns:   The first ancestor that matches the passed criteria, or null if none match.
code »
goog.dom.getCompatMode()
Returns the compatMode of the document.
Returns:   The result is either CSS1Compat or BackCompat.
code »
goog.dom.getDocument()
Gets the document object being used by the dom library.
Returns:   Document object.
code »
goog.dom.getDocumentHeight()
Calculates the height of the document.
Returns:   The height of the current document.
code »
goog.dom.getDocumentHeight_(getDocumentHeight_@win)
Calculates the height of the document of the given window. Function code copied from the opensocial gadget api: gadgets.window.adjustHeight(opt_height)
Arguments:
getDocumentHeight_@win :
No description.
Returns:   The height of the document of the given window.
code »
goog.dom.getDocumentScroll()
Gets the document scroll distance as a coordinate object.
Returns:   Object with values 'x' and 'y'.
code »
goog.dom.getDocumentScrollElement()
Gets the document scroll element.
Returns:   Scrolling element.
code »
goog.dom.getDocumentScrollElement_(getDocumentScrollElement_@doc)
Helper for getDocumentScrollElement.
Arguments:
getDocumentScrollElement_@doc :
No description.
Returns:   Scrolling element.
code »
goog.dom.getDocumentScroll_(getDocumentScroll_@doc)
Helper for getDocumentScroll.
Arguments:
getDocumentScroll_@doc :
No description.
Returns:   Object with values 'x' and 'y'.
code »
goog.dom.getDomHelper(getDomHelper@opt_element)
Gets the DomHelper object for the document where the element resides.
Arguments:
getDomHelper@opt_element :
No description.
Returns:   The DomHelper.
code »
goog.dom.getElement(getElement@element)
Alias for getElementById. If a DOM node is passed in then we just return that.
Arguments:
getElement@element :
No description.
Returns:   The element with the given ID, or the node passed in.
code »
goog.dom.getElementsByTagNameAndClass(getElementsByTagNameAndClass@opt_taggetElementsByTagNameAndClass@opt_classgetElementsByTagNameAndClass@opt_el)
{length: number}
Looks up elements by both tag and class name, using browser native functions (querySelectorAll, getElementsByTagName or getElementsByClassName) where possible. This function is a useful, if limited, way of collecting a list of DOM elements with certain characteristics. goog.dom.query offers a more powerful and general solution which allows matching on CSS3 selector expressions, but at increased cost in code size. If all you need is particular tags belonging to a single class, this function is fast and sleek.
Arguments:
getElementsByTagNameAndClass@opt_tag :
No description.
getElementsByTagNameAndClass@opt_class :
No description.
getElementsByTagNameAndClass@opt_el :
No description.
Returns: 
{length: number}
  Array-like list of elements (only a length property and numerical indices are guaranteed to exist).
code »
goog.dom.getElementsByTagNameAndClass_(getElementsByTagNameAndClass_@docgetElementsByTagNameAndClass_@opt_taggetElementsByTagNameAndClass_@opt_classgetElementsByTagNameAndClass_@opt_el)
{length: number}
Helper for getElementsByTagNameAndClass.
Arguments:
getElementsByTagNameAndClass_@doc :
No description.
getElementsByTagNameAndClass_@opt_tag :
No description.
getElementsByTagNameAndClass_@opt_class :
No description.
getElementsByTagNameAndClass_@opt_el :
No description.
Returns: 
{length: number}
  Array-like list of elements (only a length property and numerical indices are guaranteed to exist).
code »
goog.dom.getFirstElementChild(getFirstElementChild@node)
Returns the first child node that is an element.
Arguments:
getFirstElementChild@node :
No description.
Returns:   The first child node of node that is an element.
code »
goog.dom.getFrameContentDocument(getFrameContentDocument@frame)
Cross-browser function for getting the document element of a frame or iframe.
Arguments:
getFrameContentDocument@frame :
No description.
Returns:   The frame content document.
code »
goog.dom.getFrameContentWindow(getFrameContentWindow@frame)
Cross-browser function for getting the window of a frame or iframe.
Arguments:
getFrameContentWindow@frame :
No description.
Returns:   The window associated with the given frame.
code »
goog.dom.getLastElementChild(getLastElementChild@node)
Returns the last child node that is an element.
Arguments:
getLastElementChild@node :
No description.
Returns:   The last child node of node that is an element.
code »
goog.dom.getNextElementNode_(getNextElementNode_@nodegetNextElementNode_@forward)
Returns the first node that is an element in the specified direction, starting with node.
Arguments:
getNextElementNode_@node :
No description.
getNextElementNode_@forward :
No description.
Returns:   The first element.
code »
goog.dom.getNextElementSibling(getNextElementSibling@node)
Returns the first next sibling that is an element.
Arguments:
getNextElementSibling@node :
No description.
Returns:   The next sibling of node that is an element.
code »
goog.dom.getNodeAtOffset(getNodeAtOffset@parentgetNodeAtOffset@offsetgetNodeAtOffset@opt_result)
Returns the node at a given offset in a parent node. If an object is provided for the optional third parameter, the node and the remainder of the offset will stored as properties of this object.
Arguments:
getNodeAtOffset@parent :
No description.
getNodeAtOffset@offset :
No description.
getNodeAtOffset@opt_result :
No description.
Returns:   The node at the given offset.
code »
goog.dom.getNodeTextLength(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:
getNodeTextLength@node :
No description.
Returns:   The length of node's text content.
code »
goog.dom.getNodeTextOffset(getNodeTextOffset@nodegetNodeTextOffset@opt_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:
getNodeTextOffset@node :
No description.
getNodeTextOffset@opt_offsetParent :
No description.
Returns:   The text offset.
code »
goog.dom.getOuterHtml(getOuterHtml@element)
Gets the outerHTML of a node, which islike innerHTML, except that it actually contains the HTML of the node itself.
Arguments:
getOuterHtml@element :
No description.
Returns:   The outerHTML of the given element.
code »
goog.dom.getOwnerDocument(getOwnerDocument@node)
Returns the owner document for a node.
Arguments:
getOwnerDocument@node :
No description.
Returns:   The document owning the node.
code »
goog.dom.getPageScroll(getPageScroll@opt_window)
Gets the page scroll distance as a coordinate object.
Arguments:
getPageScroll@opt_window :
No description.
Returns:   Object with values 'x' and 'y'.
code »
goog.dom.getPreviousElementSibling(getPreviousElementSibling@node)
Returns the first previous sibling that is an element.
Arguments:
getPreviousElementSibling@node :
No description.
Returns:   The first previous sibling of node that is an element.
code »
goog.dom.getRawTextContent(getRawTextContent@node)
Returns the text content of the current node, without markup. Unlike getTextContent this method does not collapse whitespaces or normalize lines breaks.
Arguments:
getRawTextContent@node :
No description.
Returns:   The raw text content.
code »
goog.dom.getTextContent(getTextContent@node)
Returns the text content of the current node, without markup and invisible symbols. 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:
getTextContent@node :
No description.
Returns:   The text content.
code »
goog.dom.getTextContent_(getTextContent_@nodegetTextContent_@bufgetTextContent_@normalizeWhitespace)
Recursive support function for text content retrieval.
Arguments:
getTextContent_@node :
No description.
getTextContent_@buf :
No description.
getTextContent_@normalizeWhitespace :
No description.
code »
goog.dom.getViewportSize(getViewportSize@opt_window)
Gets the dimensions of the viewport. Gecko Standards mode: docEl.clientWidth Width of viewport excluding scrollbar. win.innerWidth Width of viewport including scrollbar. body.clientWidth Width of body element. docEl.clientHeight Height of viewport excluding scrollbar. win.innerHeight Height of viewport including scrollbar. body.clientHeight Height of document. Gecko Backwards compatible mode: docEl.clientWidth Width of viewport excluding scrollbar. win.innerWidth Width of viewport including scrollbar. body.clientWidth Width of viewport excluding scrollbar. docEl.clientHeight Height of document. win.innerHeight Height of viewport including scrollbar. body.clientHeight Height of viewport excluding scrollbar. IE6/7 Standards mode: docEl.clientWidth Width of viewport excluding scrollbar. win.innerWidth Undefined. body.clientWidth Width of body element. docEl.clientHeight Height of viewport excluding scrollbar. win.innerHeight Undefined. body.clientHeight Height of document element. IE5 + IE6/7 Backwards compatible mode: docEl.clientWidth 0. win.innerWidth Undefined. body.clientWidth Width of viewport excluding scrollbar. docEl.clientHeight 0. win.innerHeight Undefined. body.clientHeight Height of viewport excluding scrollbar. Opera 9 Standards and backwards compatible mode: docEl.clientWidth Width of viewport excluding scrollbar. win.innerWidth Width of viewport including scrollbar. body.clientWidth Width of viewport excluding scrollbar. docEl.clientHeight Height of document. win.innerHeight Height of viewport including scrollbar. body.clientHeight Height of viewport excluding scrollbar. WebKit: Safari 2 docEl.clientHeight Same as scrollHeight. docEl.clientWidth Same as innerWidth. win.innerWidth Width of viewport excluding scrollbar. win.innerHeight Height of the viewport including scrollbar. frame.innerHeight Height of the viewport exluding scrollbar. Safari 3 (tested in 522) docEl.clientWidth Width of viewport excluding scrollbar. docEl.clientHeight Height of viewport excluding scrollbar in strict mode. body.clientHeight Height of viewport excluding scrollbar in quirks mode.
Arguments:
getViewportSize@opt_window :
No description.
Returns:   Object with values 'width' and 'height'.
code »
goog.dom.getViewportSize_(getViewportSize_@win)
Helper for getViewportSize.
Arguments:
getViewportSize_@win :
No description.
Returns:   Object with values 'width' and 'height'.
code »
goog.dom.getWindow(getWindow@opt_doc)
Gets the window object associated with the given document.
Arguments:
getWindow@opt_doc :
No description.
Returns:   The window associated with the given document.
code »
goog.dom.getWindow_(getWindow_@doc)
Helper for getWindow.
Arguments:
getWindow_@doc :
No description.
Returns:   The window associated with the given document.
code »
goog.dom.htmlToDocumentFragment(htmlToDocumentFragment@htmlString)
Converts an HTML string into a document fragment.
Arguments:
htmlToDocumentFragment@htmlString :
No description.
Returns:   The resulting document fragment.
code »
goog.dom.htmlToDocumentFragment_(htmlToDocumentFragment_@dochtmlToDocumentFragment_@htmlString)
Helper for htmlToDocumentFragment.
Arguments:
htmlToDocumentFragment_@doc :
No description.
htmlToDocumentFragment_@htmlString :
No description.
Returns:   The resulting document fragment.
code »
goog.dom.insertSiblingAfter(insertSiblingAfter@newNodeinsertSiblingAfter@refNode)
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:
insertSiblingAfter@newNode :
No description.
insertSiblingAfter@refNode :
No description.
code »
goog.dom.insertSiblingBefore(insertSiblingBefore@newNodeinsertSiblingBefore@refNode)
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:
insertSiblingBefore@newNode :
No description.
insertSiblingBefore@refNode :
No description.
code »
goog.dom.isCss1CompatMode()
Returns true if the browser is in "CSS1-compatible" (standards-compliant) mode, false otherwise.
Returns:   True if in CSS1-compatible mode.
code »
goog.dom.isCss1CompatMode_(isCss1CompatMode_@doc)
Returns true if the browser is in "CSS1-compatible" (standards-compliant) mode, false otherwise.
Arguments:
isCss1CompatMode_@doc :
No description.
Returns:   True if in CSS1-compatible mode.
code »
goog.dom.isFocusableTabIndex(isFocusableTabIndex@element)
Returns true if the element has a tab index that allows it to receive keyboard focus (tabIndex >= 0), false otherwise. Note that form elements natively support keyboard focus, even if they have no tab index. See http://go/tabindex for more info.
Arguments:
isFocusableTabIndex@element :
No description.
Returns:   Whether the element has a tab index that allows keyboard focus.
code »
goog.dom.isNodeLike(isNodeLike@obj)
Whether the object looks like a DOM node.
Arguments:
isNodeLike@obj :
No description.
Returns:   Whether the object looks like a DOM node.
code »
goog.dom.isNodeList(isNodeList@val)
Returns true if the object is a NodeList. To qualify as a NodeList, the object must have a numeric length property and an item function (which has type 'string' on IE for some reason).
Arguments:
isNodeList@val :
No description.
Returns:   Whether the object is a NodeList.
code »
goog.dom.removeChildren(removeChildren@node)
Removes all the child nodes on a DOM node.
Arguments:
removeChildren@node :
No description.
code »
goog.dom.removeNode(removeNode@node)
Removes a node from its parent.
Arguments:
removeNode@node :
No description.
Returns:   The node removed if removed; else, null.
code »
goog.dom.replaceNode(replaceNode@newNodereplaceNode@oldNode)
Replaces a node in the DOM tree. Will do nothing if oldNode has no parent.
Arguments:
replaceNode@newNode :
No description.
replaceNode@oldNode :
No description.
code »
goog.dom.setFocusableTabIndex(setFocusableTabIndex@elementsetFocusableTabIndex@enable)
Enables or disables keyboard focus support on the element via its tab index. Only elements for which goog.dom.isFocusableTabIndex returns true (or elements that natively support keyboard focus, like form elements) can receive keyboard focus. See http://go/tabindex for more info.
Arguments:
setFocusableTabIndex@element :
No description.
setFocusableTabIndex@enable :
No description.
code »
goog.dom.setProperties(setProperties@elementsetProperties@properties)
Sets multiple properties on a node.
Arguments:
setProperties@element :
No description.
setProperties@properties :
No description.
code »
goog.dom.setTextContent(setTextContent@elementsetTextContent@text)
Cross-browser function for setting the text content of an element.
Arguments:
setTextContent@element :
No description.
setTextContent@text :
No description.
code »

Global Properties

goog.dom.COMPAT_MODE_KNOWN_ :
Whether we know the compatibility mode at compile time.
Code »
goog.dom.DIRECT_ATTRIBUTE_MAP_ :
Map of attributes that should be set using element.setAttribute(key, val) instead of element[key] = val. Used by goog.dom.setProperties.
Code »
goog.dom.PREDEFINED_TAG_VALUES_ :
Map of tags which have predefined values with regard to whitespace.
Code »
goog.dom.TAGS_TO_IGNORE_ :
Map of tags whose content to ignore when calculating text length.
Code »

Directory dom

File Reference