dom

Classes

goog.dom.AbstractMultiRange
Creates a new multi range with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead.
goog.dom.AbstractRange
Creates a new selection with no properties. Do not use this constructor - use one of the goog.dom.Range.from* methods instead.
goog.dom.BufferedViewportSizeMonitor
Creates a new BufferedViewportSizeMonitor.
goog.dom.ControlRange
Create a new control selection with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead.
goog.dom.ControlRangeIterator
Subclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected.
goog.dom.DomHelper
Create an instance of a DOM helper with a new document object.
goog.dom.DomSavedControlRange_
A SavedRange implementation using DOM endpoints.
goog.dom.DomSavedMultiRange_
A SavedRange implementation using DOM endpoints.
goog.dom.DomSavedTextRange_
A SavedRange implementation using DOM endpoints.
goog.dom.FontSizeMonitor
This class can be used to monitor changes in font size. Instances will dispatch a goog.dom.FontSizeMonitor.EventType.CHANGE event. Example usage:
var fms = new goog.dom.FontSizeMonitor();
goog.events.listen(fms, goog.dom.FontSizeMonitor.EventType.CHANGE,
    function(e) {
      alert('Font size was changed');
    });
goog.dom.MultiRange
Creates a new multi part range with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead.
goog.dom.MultiRangeIterator
Subclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected.
goog.dom.NodeIterator
A DOM tree traversal iterator. Starting with the given node, the iterator walks the DOM in order, reporting events for each node. The iterator acts as a prefix iterator:
<div>1<span>2</span>3</div>
Will return the following nodes: [div, 1, span, 2, 3] With the following depths [1, 1, 2, 2, 1] Imagining | represents iterator position, the traversal stops at each of the following locations:
<div>|1|<span>|2|</span>3|</div>
The iterator can also be used in reverse mode, which will return the nodes and states in the opposite order. The depths will be slightly different since, like in normal mode, the depth is computed *after* the last move. Lastly, it is possible to create an iterator that is unconstrained, meaning that it will continue iterating until the end of the document instead of until exiting the start node.
goog.dom.NodeOffset
Object to store the offset from one node to another in a way that works on any similar DOM structure regardless of whether it is the same actual nodes.
goog.dom.RangeIterator
Subclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected.
goog.dom.SavedCaretRange
A struct for holding context about saved selections. This can be used to preserve the selection and restore while the DOM is manipulated, or through an asynchronous call. Use goog.dom.Range factory methods to obtain an instance, and use to obtain a SavedCaretRange. For editor ranges under content-editable elements or design-mode iframes, prefer using .
goog.dom.SavedRange
Abstract interface for a saved range.
goog.dom.TagIterator
A DOM tree traversal iterator. Starting with the given node, the iterator walks the DOM in order, reporting events for the start and end of Elements, and the presence of text nodes. For example:
<div>1<span>2</span>3</div>
Will return the following nodes: [div, 1, span, 2, span, 3, div] With the following states: [START, OTHER, START, OTHER, END, OTHER, END] And the following depths [1, 1, 2, 2, 1, 1, 0] Imagining | represents iterator position, the traversal stops at each of the following locations:
<div>|1|<span>|2|</span>|3|</div>|
The iterator can also be used in reverse mode, which will return the nodes and states in the opposite order. The depths will be slightly different since, like in normal mode, the depth is computed *after* the given node. Lastly, it is possible to create an iterator that is unconstrained, meaning that it will continue iterating until the end of the document instead of until exiting the start node.
goog.dom.TextRange
Create a new text selection with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead.
goog.dom.TextRangeIterator
Subclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected.
goog.dom.ViewportSizeMonitor
This class can be used to monitor changes in the viewport size. Instances dispatch a goog.events.EventType.RESIZE event when the viewport size changes. Handlers can call goog.dom.ViewportSizeMonitor#getSize to get the new viewport size. Use this class if you want to execute resize/reflow logic each time the user resizes the browser window. This class is guaranteed to only dispatch RESIZE events when the pixel dimensions of the viewport change. (Internet Explorer fires resize events if any element on the page is resized, even if the viewport dimensions are unchanged, which can lead to infinite resize loops.) Example usage:
   var vsm = new goog.dom.ViewportSizeMonitor();
   goog.events.listen(vsm, goog.events.EventType.RESIZE, function(e) {
     alert('Viewport size changed to ' + vsm.getSize());
   });
 
Manually verified on IE6, IE7, FF2, Opera 11, Safari 4 and Chrome.

Public Protected Private

Enumerations

goog.dom.BrowserFeature :
Enum of browser capabilities.
Constants:
CAN_ADD_NAME_OR_TYPE_ATTRIBUTES
No description.
CAN_USE_CHILDREN_ATTRIBUTE
No description.
CAN_USE_INNER_TEXT
No description.
CAN_USE_PARENT_ELEMENT_PROPERTY
No description.
INNER_HTML_NEEDS_SCOPED_ELEMENT
No description.
Code »
goog.dom.NodeType :
Constants for the nodeType attribute in the Node interface. These constants match those specified in the Node interface. These are usually present on the Node object in recent browsers, but not in older browsers (specifically, early IEs) and thus are given here. In some browsers (early IEs), these are not defined on the Node object, so they are provided here. See http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247
Constants:
ATTRIBUTE
No description.
CDATA_SECTION
No description.
COMMENT
No description.
DOCUMENT
No description.
DOCUMENT_FRAGMENT
No description.
DOCUMENT_TYPE
No description.
ELEMENT
No description.
ENTITY
No description.
ENTITY_REFERENCE
No description.
NOTATION
No description.
PROCESSING_INSTRUCTION
No description.
TEXT
No description.
Code »
goog.dom.RangeEndpoint :
Constants for selection endpoints.
Constants:
END
No description.
START
No description.
Code »
goog.dom.RangeType :
Types of ranges.
Constants:
CONTROL
No description.
MULTI
No description.
TEXT
No description.
Code »
goog.dom.TagName :
Enum of all html tag names specified by the W3C HTML4.01 and HTML5 specifications.
Constants:
A
No description.
ABBR
No description.
ACRONYM
No description.
ADDRESS
No description.
APPLET
No description.
AREA
No description.
ARTICLE
No description.
ASIDE
No description.
AUDIO
No description.
B
No description.
BASE
No description.
BASEFONT
No description.
BDI
No description.
BDO
No description.
BIG
No description.
BLOCKQUOTE
No description.
BODY
No description.
BR
No description.
BUTTON
No description.
CANVAS
No description.
CAPTION
No description.
CENTER
No description.
CITE
No description.
CODE
No description.
COL
No description.
COLGROUP
No description.
COMMAND
No description.
DATA
No description.
DATALIST
No description.
DD
No description.
DEL
No description.
DETAILS
No description.
DFN
No description.
DIALOG
No description.
DIR
No description.
DIV
No description.
DL
No description.
DT
No description.
EM
No description.
EMBED
No description.
FIELDSET
No description.
FIGCAPTION
No description.
FIGURE
No description.
FONT
No description.
FOOTER
No description.
FORM
No description.
FRAME
No description.
FRAMESET
No description.
H1
No description.
H2
No description.
H3
No description.
H4
No description.
H5
No description.
H6
No description.
HEAD
No description.
HEADER
No description.
HGROUP
No description.
HR
No description.
HTML
No description.
I
No description.
IFRAME
No description.
IMG
No description.
INPUT
No description.
INS
No description.
ISINDEX
No description.
KBD
No description.
KEYGEN
No description.
LABEL
No description.
LEGEND
No description.
LI
No description.
LINK
No description.
MAP
No description.
MARK
No description.
MATH
No description.
MENU
No description.
META
No description.
METER
No description.
NAV
No description.
NOFRAMES
No description.
NOSCRIPT
No description.
OBJECT
No description.
OL
No description.
OPTGROUP
No description.
OPTION
No description.
OUTPUT
No description.
P
No description.
PARAM
No description.
PRE
No description.
PROGRESS
No description.
Q
No description.
RP
No description.
RT
No description.
RUBY
No description.
S
No description.
SAMP
No description.
SCRIPT
No description.
SECTION
No description.
SELECT
No description.
SMALL
No description.
SOURCE
No description.
SPAN
No description.
STRIKE
No description.
STRONG
No description.
STYLE
No description.
SUB
No description.
SUMMARY
No description.
SUP
No description.
SVG
No description.
TABLE
No description.
TBODY
No description.
TD
No description.
TEXTAREA
No description.
TFOOT
No description.
TH
No description.
THEAD
No description.
TIME
No description.
TITLE
No description.
TR
No description.
TRACK
No description.
TT
No description.
U
No description.
UL
No description.
VAR
No description.
VIDEO
No description.
WBR
No description.
Code »
goog.dom.TagWalkType :
There are three types of token:
  1. START_TAG - The beginning of a tag.
  2. OTHER - Any non-element node position.
  3. END_TAG - The end of a tag.
Users of this enumeration can rely on START_TAG + END_TAG = 0 and that OTHER = 0.
Constants:
END_TAG
No description.
OTHER
No description.
START_TAG
No description.
Code »

Global Functions

goog.dom.$(element) Element
Use goog.dom.getElement instead. Alias for getElement.
Arguments:
element : string | Element
Element ID or a DOM node.
Returns: Element  The element with the given ID, or the node passed in.
code »
goog.dom.$$(opt_tagopt_classopt_el) {length: number
Use goog.dom.getElementsByTagNameAndClass instead. Alias for getElementsByTagNameAndClass.
Arguments:
opt_tag : ?string=
Element tag name.
opt_class : ?string=
Optional class name.
opt_el : Element=
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 »
goog.dom.$dom(tagNameopt_attributesvar_args) !Element
Use goog.dom.createDom instead. Alias for createDom.
Arguments:
tagName : string
Tag to create.
opt_attributes : (string | Object)=
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 | string | Array | NodeList)
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: !Element  Reference to a DOM node.
code »
goog.dom.append(parentvar_args)
Appends a node with text or other nodes.
Arguments:
parent : !Node
The node to append nodes to.
var_args : ...goog.dom.Appendable
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 »
goog.dom.appendChild(parentchild)
Appends a child to a node.
Arguments:
parent : Node
Parent.
child : Node
Child.
code »
goog.dom.append_(docparentargsstartIndex)
Appends a node with text or other nodes.
Arguments:
doc : !Document
The document to create new nodes in.
parent : !Node
The node to append nodes to.
args : !Arguments
The values to add. See goog.dom.append.
startIndex : number
The index of the array to start from.
code »
goog.dom.canHaveChildren(node) boolean
Determines if the given node can contain children, intended to be used for HTML generation. IE natively supports node.canHaveChildren but has inconsistent behavior. Prior to IE8 the base tag allows children and in IE9 all nodes return true for canHaveChildren. In practice all non-IE browsers allow you to add children to any node, but the behavior is inconsistent:
  var a = document.createElement('br');
  a.appendChild(document.createTextNode('foo'));
  a.appendChild(document.createTextNode('bar'));
  console.log(a.childNodes.length);  // 2
  console.log(a.innerHTML);  // Chrome: "", IE9: "foobar", FF3.5: "foobar"
For more information, see: http://dev.w3.org/html5/markup/syntax.html#syntax-elements TODO(user): Rename shouldAllowChildren() ?
Arguments:
node : Node
The node to check.
Returns: boolean  Whether the node can contain children.
code »
goog.dom.canUseQuerySelector_(parent) boolean
Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and fast W3C Selectors API.
Arguments:
parent : !(Element | Document)
The parent document object.
Returns: boolean  whether or not we can use parent.querySelector* APIs.
code »
goog.dom.compareNodeOrder(node1node2) number
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:
node1 : Node
The first node to compare.
node2 : Node
The second node to compare.
Returns: number  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_(textNodenode) number
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:
textNode : Node
The textNode to compare.
node : Node
The node to compare.
Returns: number  -1 if node is before textNode, +1 otherwise.
code »
goog.dom.compareSiblingOrder_(node1node2) number
Utility function to compare the position of two nodes known to be non-equal siblings.
Arguments:
node1 : Node
The first node to compare.
node2 : Node
The second node to compare.
Returns: number  -1 if node1 is before node2, +1 otherwise.
code »
goog.dom.contains(parentdescendant) boolean
Whether a node contains another node.
Arguments:
parent : Node
The node that should contain the other node.
descendant : Node
The node to test presence of.
Returns: boolean  Whether the parent node contains the descendent node.
code »
goog.dom.createDom(tagNameopt_attributesvar_args) !Element
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:
tagName : string
Tag to create.
opt_attributes : (Object | Array.<string> | string)=
If object, then a map of name-value pairs for attributes. If a string, then this is the className of the new element. If an array, the elements will be joined together as the className of the new element.
var_args : ...(Object | string | Array | NodeList)
Further DOM nodes or strings for text nodes. If one of the var_args is an array or NodeList,i its elements will be added as childNodes instead.
Returns: !Element  Reference to a DOM node.
code »
goog.dom.createDom_(docargs) !Element
Helper for createDom.
Arguments:
doc : !Document
The document to create the DOM in.
args : !Arguments
Argument object passed from the callers. See goog.dom.createDom for details.
Returns: !Element  Reference to a DOM node.
code »
goog.dom.createElement(name) !Element
Creates a new element.
Arguments:
name : string
Tag name.
Returns: !Element  The new element.
code »
goog.dom.createTable(rowscolumnsopt_fillWithNbsp) !Element
Create a table.
Arguments:
rows : number
The number of rows in the table. Must be >= 1.
columns : number
The number of columns in the table. Must be >= 1.
opt_fillWithNbsp : boolean=
If true, fills table entries with nsbps.
Returns: !Element  The created table.
code »
goog.dom.createTable_(docrowscolumnsfillWithNbsp) !Element
Create a table.
Arguments:
doc : !Document
Document object to use to create the table.
rows : number
The number of rows in the table. Must be >= 1.
columns : number
The number of columns in the table. Must be >= 1.
fillWithNbsp : boolean
If true, fills table entries with nsbps.
Returns: !Element  The created table.
code »
goog.dom.createTextNode(content) !Text
Creates a new text node.
Arguments:
content : number | string
Content.
Returns: !Text  The new text node.
code »
goog.dom.findCommonAncestor(var_args) Node
Find the deepest common ancestor of the given nodes.
Arguments:
var_args : ...Node
The nodes to find a common ancestor of.
Returns: Node  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(rootp) 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:
root : Node
The root of the tree to search.
p : function(Node) : boolean
The filter function.
Returns: Node | undefined  The found node or undefined if none is found.
code »
goog.dom.findNodes(p) !Array.<!Node>
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. @param {Node} root The root of the tree to search.
Arguments:
p : function(Node) : boolean
The filter function.
Returns: !Array.<!Node>  The found nodes or an empty array if none are found.
code »
goog.dom.findNodes_(rootprvfindOne) boolean
Finds the first or all the descendant nodes that match the filter function, using a depth first search.
Arguments:
root : Node
The root of the tree to search.
p : function(Node) : boolean
The filter function.
rv : !Array.<!Node>
The found nodes are added to this array.
findOne : boolean
If true we exit after the first found node.
Returns: boolean  Whether the search is complete or not. True in case findOne is true and the node is found. False otherwise.
code »
goog.dom.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:
element : Element
The element to flatten.
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.getActiveElement(doc) Element
Determines the active element in the given document.
Arguments:
doc : Document
The document to look in.
Returns: Element  The active element.
code »
goog.dom.getAncestor(elementmatcheropt_includeNodeopt_maxSearchSteps) Node
Walks up the DOM hierarchy returning the first ancestor that passes the matcher function.
Arguments:
element : Node
The DOM node to start with.
matcher : function(Node) : boolean
A function that returns true if the passed node matches the desired criteria.
opt_includeNode : boolean=
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=
Maximum number of levels to search up the dom.
Returns: Node  DOM node that matched the matcher, or null if there was no match.
code »
goog.dom.getAncestorByClass(elementclassName) Element
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
The DOM node to start with.
className : string
The class name to match.
Returns: Element  The first ancestor that matches the passed criteria, or null if none match.
code »
goog.dom.getAncestorByTagNameAndClass(elementopt_tagopt_class) Element
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
The DOM node to start with.
opt_tag : ?(goog.dom.TagName | string)=
The tag name to match (or null/undefined to match only based on class name).
opt_class : ?string=
The class name to match (or null/undefined to match only based on tag name).
Returns: Element  The first ancestor that matches the passed criteria, or null if no match is found.
code »
goog.dom.getChildren(element) !(Array | NodeList)
Returns an array containing just the element children of the given element.
Arguments:
element : Element
The element whose element children we want.
Returns: !(Array | NodeList)  An array or array-like list of just the element children of the given element.
code »
goog.dom.getDocument() !Document
Gets the document object being used by the dom library.
Returns: !Document  Document object.
code »
goog.dom.getDocumentHeight() number
Calculates the height of the document.
Returns: number  The height of the current document.
code »
goog.dom.getDocumentHeight_(win) number
Calculates the height of the document of the given window. Function code copied from the opensocial gadget api: gadgets.window.adjustHeight(opt_height)
Arguments:
win : Window
The window whose document height to retrieve.
Returns: number  The height of the document of the given window.
code »
goog.dom.getDocumentScroll() !goog.math.Coordinate
Gets the document scroll distance as a coordinate object.
Returns: !goog.math.Coordinate  Object with values 'x' and 'y'.
code »
goog.dom.getDocumentScrollElement() !Element
Gets the document scroll element.
Returns: !Element  Scrolling element.
code »
goog.dom.getDocumentScrollElement_(doc) !Element
Helper for getDocumentScrollElement.
Arguments:
doc : !Document
The document to get the scroll element for.
Returns: !Element  Scrolling element.
code »
goog.dom.getDocumentScroll_(doc) !goog.math.Coordinate
Helper for getDocumentScroll.
Arguments:
doc : !Document
The document to get the scroll for.
Returns: !goog.math.Coordinate  Object with values 'x' and 'y'.
code »
goog.dom.getDomHelper(opt_element) !goog.dom.DomHelper
Gets the DomHelper object for the document where the element resides.
Arguments:
opt_element : (Node | Window)=
If present, gets the DomHelper for this element.
Returns: !goog.dom.DomHelper  The DomHelper.
code »
goog.dom.getElement(element) Element
Gets an element from the current document by element id. If an Element is passed in, it is returned.
Arguments:
element : string | Element
Element ID or a DOM node.
Returns: Element  The element with the given ID, or the node passed in.
code »
goog.dom.getElementByClass(classNameopt_el) Element
Returns the first element with the provided className.
Arguments:
className : string
the name of the class to look for.
opt_el : Element | Document=
Optional element to look in.
Returns: Element  The first item with the class name provided.
code »
goog.dom.getElementHelper_(docelement) Element
Gets an element by id from the given document (if present). If an element is given, it is returned.
Arguments:
doc : !Document
No description.
element : string | Element
Element ID or a DOM node.
Returns: Element  The resulting element.
code »
goog.dom.getElementsByClass(classNameopt_el) {length: number
Returns a static, array-like list of the elements with the provided className.
Arguments:
className : string
the name of the class to look for.
opt_el : (Document | Element)=
Optional element to look in.
Returns:  {length: number  } The items found with the class name provided.
code »
goog.dom.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. 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. Note that tag names are case sensitive in the SVG namespace, and this function converts opt_tag to uppercase for comparisons. For queries in the SVG namespace you should use querySelector or querySelectorAll instead. https://bugzilla.mozilla.org/show_bug.cgi?id=963870 https://bugs.webkit.org/show_bug.cgi?id=83438
Arguments:
opt_tag : ?string=
Element tag name.
opt_class : ?string=
Optional class name.
opt_el : (Document | Element)=
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 »
goog.dom.getElementsByTagNameAndClass_(docopt_tagopt_classopt_el) {length: number
Helper for getElementsByTagNameAndClass.
Arguments:
doc : !Document
The document to get the elements in.
opt_tag : ?string=
Element tag name.
opt_class : ?string=
Optional class name.
opt_el : (Document | Element)=
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 »
goog.dom.getFirstElementChild(node) Element
Returns the first child node that is an element.
Arguments:
node : Node
The node to get the first child element of.
Returns: Element  The first child node of node that is an element.
code »
goog.dom.getFrameContentDocument(frame) !Document
Cross-browser function for getting the document element of a frame or iframe.
Arguments:
frame : Element
Frame element.
Returns: !Document  The frame content document.
code »
goog.dom.getFrameContentWindow(frame) Window
Cross-browser function for getting the window of a frame or iframe.
Arguments:
frame : Element
Frame element.
Returns: Window  The window associated with the given frame.
code »
goog.dom.getLastElementChild(node) Element
Returns the last child node that is an element.
Arguments:
node : Node
The node to get the last child element of.
Returns: Element  The last child node of node that is an element.
code »
goog.dom.getNextElementNode_(nodeforward) Element
Returns the first node that is an element in the specified direction, starting with node.
Arguments:
node : Node
The node to get the next element from.
forward : boolean
Whether to look forwards or backwards.
Returns: Element  The first element.
code »
goog.dom.getNextElementSibling(node) Element
Returns the first next sibling that is an element.
Arguments:
node : Node
The node to get the next sibling element of.
Returns: Element  The next sibling of node that is an element.
code »
goog.dom.getNextNode(node) Node
Returns the next node in source order from the given node.
Arguments:
node : Node
The node.
Returns: Node  The next node in the DOM tree, or null if this was the last node.
code »
goog.dom.getNodeAtOffset(parentoffsetopt_result) Node
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:
parent : Node
The parent node.
offset : number
The offset into the parent node.
opt_result : Object=
Object to be used to store the return value. The return value will be stored in the form {node: Node, remainder: number} if this object is provided.
Returns: Node  The node at the given offset.
code »
goog.dom.getNodeTextLength(node) number
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
The node whose text content length is being calculated.
Returns: number  The length of node's text content.
code »
goog.dom.getNodeTextOffset(nodeopt_offsetParent) number
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
The node whose offset is being calculated.
opt_offsetParent : Node=
The node relative to which the offset will be calculated. Defaults to the node's owner document's body.
Returns: number  The text offset.
code »
goog.dom.getOuterHtml(element) string
Gets the outerHTML of a node, which islike innerHTML, except that it actually contains the HTML of the node itself.
Arguments:
element : Element
The element to get the HTML of.
Returns: string  The outerHTML of the given element.
code »
goog.dom.getOwnerDocument(node) !Document
Returns the owner document for a node.
Arguments:
node : Node | Window
The node to get the document for.
Returns: !Document  The document owning the node.
code »
goog.dom.getPageScroll(opt_window) !goog.math.Coordinate
Use goog.dom.getDocumentScroll instead. Gets the page scroll distance as a coordinate object.
Arguments:
opt_window : Window=
Optional window element to test.
Returns: !goog.math.Coordinate  Object with values 'x' and 'y'.
code »
goog.dom.getParentElement(element) Element
Returns an element's parent, if it's an Element.
Arguments:
element : Element
The DOM element.
Returns: Element  The parent, or null if not an Element.
code »
goog.dom.getPixelRatio() number
Gives the devicePixelRatio, or attempts to determine if not present. By default, this is the same value given by window.devicePixelRatio. If devicePixelRatio is not defined, the ratio is calculated with window.matchMedia, if present. Otherwise, gives 1.0. This function is cached so that the pixel ratio is calculated only once and only calculated when first requested.
Returns: number  The number of actual pixels per virtual pixel.
code »
goog.dom.getPreviousElementSibling(node) Element
Returns the first previous sibling that is an element.
Arguments:
node : Node
The node to get the previous sibling element of.
Returns: Element  The first previous sibling of node that is an element.
code »
goog.dom.getPreviousNode(node) Node
Returns the previous node in source order from the given node.
Arguments:
node : Node
The node.
Returns: Node  The previous node in the DOM tree, or null if this was the first node.
code »
goog.dom.getRawTextContent(node) string
Returns the text content of the current node, without markup. Unlike getTextContent this method does not collapse whitespaces or normalize lines breaks.
Arguments:
node : Node
The node from which we are getting content.
Returns: string  The raw text content.
code »
goog.dom.getRequiredElement(id) !Element
Gets an element by id, asserting that the element is found. This is used when an element is expected to exist, and should fail with an assertion error if it does not (if assertions are enabled).
Arguments:
id : string
Element ID.
Returns: !Element  The element with the given ID, if it exists.
code »
goog.dom.getRequiredElementByClass(classNameopt_root) !Element
Ensures an element with the given className exists, and then returns the first element with the provided className.
Arguments:
className : string
the name of the class to look for.
opt_root : !Element | !Document=
Optional element or document to look in.
Returns: !Element  The first item with the class name provided.
code »
goog.dom.getRequiredElementHelper_(docid) !Element
Helper function for getRequiredElementHelper functions, both static and on DomHelper. Asserts the element with the given id exists.
Arguments:
doc : !Document
No description.
id : string
No description.
Returns: !Element  The element with the given ID, if it exists.
code »
goog.dom.getTextContent(node) string
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:
node : Node
The node from which we are getting content.
Returns: string  The text content.
code »
goog.dom.getTextContent_(nodebufnormalizeWhitespace)
Recursive support function for text content retrieval.
Arguments:
node : Node
The node from which we are getting content.
buf : Array
string buffer.
normalizeWhitespace : boolean
Whether to normalize whitespace.
code »
goog.dom.getViewportSize(opt_window) !goog.math.Size
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:
opt_window : Window=
Optional window element to test.
Returns: !goog.math.Size  Object with values 'width' and 'height'.
code »
goog.dom.getViewportSize_(win) !goog.math.Size
Helper for getViewportSize.
Arguments:
win : Window
The window to get the view port size for.
Returns: !goog.math.Size  Object with values 'width' and 'height'.
code »
goog.dom.getWindow(opt_doc) !Window
Gets the window object associated with the given document.
Arguments:
opt_doc : Document=
Document object to get window for.
Returns: !Window  The window associated with the given document.
code »
goog.dom.getWindow_(doc) !Window
Helper for getWindow.
Arguments:
doc : !Document
Document object to get window for.
Returns: !Window  The window associated with the given document.
code »
goog.dom.hasNonZeroBoundingRect_(element) boolean
Returns true if the element has a bounding rectangle that would be visible (i.e. its width and height are greater than zero).
Arguments:
element : Element
Element to check.
Returns: boolean  Whether the element has a non-zero bounding rectangle.
code »
goog.dom.hasSpecifiedTabIndex_(element) boolean
Returns true if the element has a specified tab index.
Arguments:
element : Element
Element to check.
Returns: boolean  Whether the element has a specified tab index.
code »
goog.dom.htmlToDocumentFragment(htmlString) !Node
Converts an HTML string into a document fragment. The string must be sanitized in order to avoid cross-site scripting. For example goog.dom.htmlToDocumentFragment('&lt;img src=x onerror=alert(0)&gt;') triggers an alert in all browsers, even if the returned document fragment is thrown away immediately.
Arguments:
htmlString : string
The HTML string to convert.
Returns: !Node  The resulting document fragment.
code »
goog.dom.htmlToDocumentFragment_(dochtmlString) !Node
Helper for htmlToDocumentFragment.
Arguments:
doc : !Document
The document.
htmlString : string
The HTML string to convert.
Returns: !Node  The resulting document fragment.
code »
goog.dom.insertChildAt(parentchildindex)
Insert a child at a given index. If index is larger than the number of child nodes that the parent currently has, the node is inserted as the last child node.
Arguments:
parent : Element
The element into which to insert the child.
child : Node
The element to insert.
index : number
The index at which to insert the new child node. Must not be negative.
code »
goog.dom.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
Node to insert.
refNode : Node
Reference node to insert after.
code »
goog.dom.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
Node to insert.
refNode : Node
Reference node to insert before.
code »
goog.dom.isCss1CompatMode() boolean
Returns true if the browser is in "CSS1-compatible" (standards-compliant) mode, false otherwise.
Returns: boolean  True if in CSS1-compatible mode.
code »
goog.dom.isCss1CompatMode_(doc) boolean
Returns true if the browser is in "CSS1-compatible" (standards-compliant) mode, false otherwise.
Arguments:
doc : Document
The document to check.
Returns: boolean  True if in CSS1-compatible mode.
code »
goog.dom.isElement(obj) boolean
Whether the object looks like an Element.
Arguments:
obj : ?
The object being tested for Element likeness.
Returns: boolean  Whether the object looks like an Element.
code »
goog.dom.isFocusable(element) boolean
Returns true if the element can be focused, i.e. it has a tab index that allows it to receive keyboard focus (tabIndex >= 0), or it is an element that natively supports keyboard focus.
Arguments:
element : Element
Element to check.
Returns: boolean  Whether the element allows keyboard focus.
code »
goog.dom.isFocusableTabIndex(element) boolean
Returns true if the element has a tab index that allows it to receive keyboard focus (tabIndex >= 0), false otherwise. Note that some elements natively support keyboard focus, even if they have no tab index.
Arguments:
element : Element
Element to check.
Returns: boolean  Whether the element has a tab index that allows keyboard focus.
code »
goog.dom.isNodeLike(obj) boolean
Whether the object looks like a DOM node.
Arguments:
obj : ?
The object being tested for node likeness.
Returns: boolean  Whether the object looks like a DOM node.
code »
goog.dom.isNodeList(val) boolean
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:
val : Object
Object to test.
Returns: boolean  Whether the object is a NodeList.
code »
goog.dom.isTabIndexFocusable_(element) boolean
Returns true if the element's tab index allows the element to be focused.
Arguments:
element : Element
Element to check.
Returns: boolean  Whether the element's tab index allows focus.
code »
goog.dom.isWindow(obj) boolean
Returns true if the specified value is a Window object. This includes the global window for HTML pages, and iframe windows.
Arguments:
obj : ?
Variable to test.
Returns: boolean  Whether the variable is a window.
code »
goog.dom.matchesPixelRatio_(pixelRatio) number
Calculates a mediaQuery to check if the current device supports the given actual to virtual pixel ratio.
Arguments:
pixelRatio : number
The ratio of actual pixels to virtual pixels.
Returns: number  pixelRatio if applicable, otherwise 0.
code »
goog.dom.nativelySupportsFocus_(element) boolean
Returns true if the element is focusable even when tabIndex is not set.
Arguments:
element : Element
Element to check.
Returns: boolean  Whether the element natively supports focus.
code »
goog.dom.query(queryopt_root) {length: number
This is an all-software query selector. Use document.querySelector. See https://developer.mozilla.org/en-US/docs/DOM/Document.querySelector . Returns nodes which match the given CSS3 selector, searching the entire document by default but optionally taking a node to scope the search by. dojo.query() is the swiss army knife of DOM node manipulation in Dojo. Much like Prototype's "$$" (bling-bling) function or JQuery's "$" function, dojo.query provides robust, high-performance CSS-based node selector support with the option of scoping searches to a particular sub-tree of a document. Supported Selectors: -------------------- dojo.query() supports a rich set of CSS3 selectors, including: * class selectors (e.g., `.foo`) * node type selectors like `span` * ` ` descendant selectors * `>` child element selectors * `#foo` style ID selectors * `*` universal selector * `~`, the immediately preceded-by sibling selector * `+`, the preceded-by sibling selector * attribute queries: | * `[foo]` attribute presence selector | * `[foo='bar']` attribute value exact match | * `[foo~='bar']` attribute value list item match | * `[foo^='bar']` attribute start match | * `[foo$='bar']` attribute end match | * `[foo*='bar']` attribute substring match * `:first-child`, `:last-child` positional selectors * `:empty` content empty selector * `:empty` content empty selector * `:nth-child(n)`, `:nth-child(2n+1)` style positional calculations * `:nth-child(even)`, `:nth-child(odd)` positional selectors * `:not(...)` negation pseudo selectors Any legal combination of these selectors will work with `dojo.query()`, including compound selectors ("," delimited). Very complex and useful searches can be constructed with this palette of selectors. Unsupported Selectors: ---------------------- While dojo.query handles many CSS3 selectors, some fall outside of what's reasonable for a programmatic node querying engine to handle. Currently unsupported selectors include: * namespace-differentiated selectors of any form * all `::` pseudo-element selectors * certain pseudo-selectors which don't get a lot of day-to-day use: | * `:root`, `:lang()`, `:target`, `:focus` * all visual and state selectors: | * `:root`, `:active`, `:hover`, `:visited`, `:link`, `:enabled`, `:disabled`, `:checked` * `:*-of-type` pseudo selectors dojo.query and XML Documents: ----------------------------- `dojo.query` currently only supports searching XML documents whose tags and attributes are 100% lower-case. This is a known limitation and will [be addressed soon] (http://trac.dojotoolkit.org/ticket/3866) Non-selector Queries: --------------------- If something other than a String is passed for the query, `dojo.query` will return a new array constructed from that parameter alone and all further processing will stop. This means that if you have a reference to a node or array or nodes, you can quickly construct a new array of nodes from the original by calling `dojo.query(node)` or `dojo.query(array)`. example: search the entire document for elements with the class "foo": | dojo.query(".foo"); these elements will match: | | |

example: search the entire document for elements with the classes "foo" *and* "bar": | dojo.query(".foo.bar"); these elements will match: | while these will not: | |

example: find `` elements which are descendants of paragraphs and which have a "highlighted" class: | dojo.query("p span.highlighted"); the innermost span in this fragment matches: |

| ... | ... | |

example: find all odd table rows inside of the table `#tabular_data`, using the `>` (direct child) selector to avoid affecting any nested tables: | dojo.query("#tabular_data > tbody > tr:nth-child(odd)");
Arguments:
query : string | Array
The CSS3 expression to match against. For details on the syntax of CSS3 selectors, see http://www.w3.org/TR/css3-selectors/#selectors.
opt_root : (string | Node)=
A Node (or node id) to scope the search from (optional).
Returns:  {length: number  } The elements that matched the query.
code »
goog.dom.removeChildren(node)
Removes all the child nodes on a DOM node.
Arguments:
node : Node
Node to remove children from.
code »
goog.dom.removeNode(node) Node
Removes a node from its parent.
Arguments:
node : Node
The node to remove.
Returns: Node  The node removed if removed; else, null.
code »
goog.dom.replaceNode(newNodeoldNode)
Replaces a node in the DOM tree. Will do nothing if oldNode has no parent.
Arguments:
newNode : Node
Node to insert.
oldNode : Node
Node to replace.
code »
goog.dom.setFocusableTabIndex(elementenable)
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:
element : Element
Element whose tab index is to be changed.
enable : boolean
Whether to set or remove a tab index on the element that supports keyboard focus.
code »
goog.dom.setProperties(elementproperties)
Sets multiple properties on a node.
Arguments:
element : Element
DOM node to set properties on.
properties : Object
Hash of property:value pairs.
code »
goog.dom.setTextContent(nodetext)
Sets the text content of a node, with cross-browser support.
Arguments:
node : Node
The node to change the text content of.
text : string | number
The value that should replace the node's content.
code »

Global Properties

goog.dom.$F :
Alias for goog.dom.form.element.getValue
Code »
goog.dom.ASSUME_QUIRKS_MODE :
No description.
Code »
goog.dom.ASSUME_STANDARDS_MODE :
No description.
Code »
goog.dom.AbstractRangeTest :
No description.
Code »
goog.dom.Appendable :
Typedef for use with goog.dom.createDom and goog.dom.append.
Code »
goog.dom.BufferedViewportSizeMonitorTest :
No description.
Code »
goog.dom.COMPAT_MODE_KNOWN_ :
Whether we know the compatibility mode at compile time.
Code »
goog.dom.ControlRangeTest :
No description.
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.FontSizeMonitorTest :
No description.
Code »
goog.dom.MultiRangeTest :
No description.
Code »
goog.dom.NodeIteratorTest :
No description.
Code »
goog.dom.NodeOffsetTest :
No description.
Code »
goog.dom.PREDEFINED_TAG_VALUES_ :
Map of tags which have predefined values with regard to whitespace.
Code »
goog.dom.Range :
No description.
Code »
goog.dom.RangeTest :
No description.
Code »
goog.dom.SavedCaretRangeTest :
No description.
Code »
goog.dom.SavedRangeTest :
No description.
Code »
goog.dom.TAGS_TO_IGNORE_ :
Map of tags whose content to ignore when calculating text length.
Code »
goog.dom.TagIteratorTest :
No description.
Code »
goog.dom.TagNameTest :
No description.
Code »
goog.dom.TextRangeIteratorTest :
No description.
Code »
goog.dom.TextRangeTest :
No description.
Code »
goog.dom.ViewportSizeMonitorTest :
No description.
Code »
goog.dom.animationFrame :
No description.
Code »
goog.dom.annotate :
No description.
Code »
goog.dom.annotateTest :
No description.
Code »
goog.dom.browserrange :
No description.
Code »
goog.dom.browserrangeTest :
No description.
Code »
goog.dom.classes :
No description.
Code »
goog.dom.classes_test :
No description.
Code »
goog.dom.classlist :
No description.
Code »
goog.dom.classlist_test :
No description.
Code »
goog.dom.dataset :
No description.
Code »
goog.dom.datasetTest :
No description.
Code »
goog.dom.defaultDomHelper_ : goog.dom.DomHelper
Cached default DOM helper.
Code »
goog.dom.devicePixelRatio_ :
No description.
Code »
goog.dom.dom_test :
No description.
Code »
goog.dom.forms :
No description.
Code »
goog.dom.formsTest :
No description.
Code »
goog.dom.fullscreen :
No description.
Code »
goog.dom.iframe :
No description.
Code »
goog.dom.iframeTest :
No description.
Code »
goog.dom.iter :
No description.
Code »
goog.dom.iterTest :
No description.
Code »
goog.dom.pattern :
No description.
Code »
goog.dom.patternTest :
No description.
Code »
goog.dom.safe :
No description.
Code »
goog.dom.safeTest :
No description.
Code »
goog.dom.selection :
No description.
Code »
goog.dom.selectionTest :
No description.
Code »
goog.dom.tags :
No description.
Code »
goog.dom.tagsTest :
No description.
Code »
goog.dom.vendor :
No description.
Code »
goog.dom.vendorTest :
No description.
Code »
goog.dom.xml :
No description.
Code »
goog.dom.xmlTest :
No description.
Code »

Package dom

Package Reference