goog.dom
Namespace.$
[deprecated]Deprecated. Use {@link goog.dom.getElement} instead.
Alias for getElement.
element
{string
|Element
}
Element
}
.$$
[deprecated]Deprecated. Use {@link goog.dom.getElementsByTagNameAndClass} instead.
Alias for {@code getElementsByTagNameAndClass}.
opt_tag
{?string
=}
opt_class
{?string
=}
opt_el
{Element
=}
length
: number
}}
.$F
[deprecated] {Function
}Deprecated. Use {@link goog.dom.forms.getValue} instead.
Alias for goog.dom.form.element.getValue
.$dom
[deprecated]Deprecated. Use {@link goog.dom.createDom} instead.
Alias for {@code createDom}.
tagName
{string
}
opt_attributes
{(string
|Object
)=}
var_args
{...(Object
|string
|Array
|NodeList
)}
Element
}
.ASSUME_QUIRKS_MODE
.ASSUME_STANDARDS_MODE
goog.dom.AbstractMultiRange
ClassCreates a new multi range with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead. … more
goog.dom.AbstractRange
ClassCreates a new selection with no properties. Do not use this constructor - use one of the goog.dom.Range.from* methods instead. … more
.Appendable
Typedef for use with goog.dom.createDom and goog.dom.append.
goog.dom.BrowserFeature
EnumEnum of browser capabilities. … more
goog.dom.ControlRange
ClassCreate a new control selection with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead. … more
goog.dom.ControlRangeIterator
ClassSubclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected. … more
goog.dom.DomHelper
ClassCreate an instance of a DOM helper with a new document object. … more
goog.dom.FontSizeMonitor
ClassThis class can be used to monitor changes in font size. Instances will dispatch a {@code 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'); });… more
goog.dom.MultiRange
ClassCreates a new multi part range with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead. … more
goog.dom.MultiRangeIterator
ClassSubclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected. … more
goog.dom.NodeIterator
ClassA 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. … more
goog.dom.NodeOffset
ClassObject 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. … more
goog.dom.NodeType
EnumEnumeration for DOM node types (for reference) … more
goog.dom.Range
Namespacegoog.dom.RangeEndpoint
EnumConstants for selection endpoints. … more
goog.dom.RangeIterator
ClassSubclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected. … more
goog.dom.RangeType
EnumTypes of ranges. … more
goog.dom.SavedCaretRange
ClassA 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 {@see goog.dom.AbstractRange} instance, and use {@see goog.dom.AbstractRange#saveUsingCarets} to obtain a SavedCaretRange. For editor ranges under content-editable elements or design-mode iframes, prefer using {@see goog.editor.range.saveUsingNormalizedCarets}. … more
goog.dom.SavedRange
ClassAbstract interface for a saved range. … more
goog.dom.TagIterator
ClassA 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. … more
goog.dom.TagName
EnumEnum of all html tag names specified by the W3C HTML4.01 and HTML5 specifications. … more
goog.dom.TagWalkType
EnumThere are three types of token:
goog.dom.TextRange
ClassCreate a new text selection with no properties. Do not use this constructor: use one of the goog.dom.Range.createFrom* methods instead. … more
goog.dom.TextRangeIterator
ClassSubclass of goog.dom.TagIterator that iterates over a DOM range. It adds functions to determine the portion of each text node that is selected. … more
goog.dom.ViewportSizeMonitor
ClassThis class can be used to monitor changes in the viewport size. Instances dispatch a {@link goog.events.EventType.RESIZE} event when the viewport size changes. Handlers can call {@link 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 {@code 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 9, and WebKit. {@code getSize} doesn't always return the correct viewport height on Safari 2.0.4. … more
goog.dom.a11y
Namespacegoog.dom.annotate
Namespace.append(parent, var_args)
Appends a node with text or other nodes.
parent
{!Node
}
var_args
{...goog.dom.Appendable
}
.appendChild(parent, child)
Appends a child to a node.
parent
{Node
}
child
{Node
}
goog.dom.browserrange
Namespace.canHaveChildren(node)
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"TODO(user): Rename shouldAllowChildren() ?
node
{Node
}
boolean
}
goog.dom.classes
Namespace.classes_test
.compareNodeOrder(node1, 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.
node1
{Node
}
node2
{Node
}
number
}
.contains(parent, descendant)
Whether a node contains another node.
parent
{Node
}
descendant
{Node
}
boolean
}
.createDom(tagName, opt_attributes, 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
tagName
{string
}
opt_attributes
{(Object
|Array
.<string
>|string
)=}
var_args
{...(Object
|string
|Array
|NodeList
)}
Element
}
.createElement(name)
Creates a new element.
name
{string
}
Element
}
.createTable(rows, columns, opt_fillWithNbsp)
Create a table.
rows
{number
}
columns
{number
}
opt_fillWithNbsp
{boolean
=}
Element
}
.createTextNode(content)
Creates a new text node.
content
{string
}
Text
}
goog.dom.dataset
Namespace.dom_test
.findCommonAncestor(var_args)
Find the deepest common ancestor of the given nodes.
var_args
{...Node
}
Node
}
.findNode(root, p)
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 {@code 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.
root
{Node
}
p
{function
(Node
) : boolean
}
Node
|undefined
}
.findNodes(root, 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 {@code 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.
root
{Node
}
p
{function
(Node
) : boolean
}
Array
.<!Node
>}
.flattenElement(element)
Flattens an element. That is, removes it and replace it with its children. Does nothing if the element is not in the document.
element
{Element
}
Element
|undefined
}
goog.dom.forms
Namespacegoog.dom.fullscreen
Namespace.getActiveElement(doc)
Determines the active element in the given document.
doc
{Document
}
Element
}
.getAncestor(element, matcher, opt_includeNode, opt_maxSearchSteps)
Walks up the DOM hierarchy returning the first ancestor that passes the matcher function.
element
{Node
}
matcher
{function
(Node
) : boolean
}
opt_includeNode
{boolean
=}
opt_maxSearchSteps
{number
=}
Node
}
.getAncestorByClass(element, className)
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.
element
{Node
}
className
{string
}
Element
}
.getAncestorByTagNameAndClass(element, opt_tag, 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.
element
{Node
}
opt_tag
{?(goog.dom.TagName
|string
)=}
opt_class
{?string
=}
Element
}
.getChildren(element)
Returns an array containing just the element children of the given element.
element
{Element
}
Array
|NodeList
)}
.getCompatMode()
[deprecated]Deprecated. use goog.dom.isCss1CompatMode instead.
Returns the compatMode of the document.
string
}
.getDocument()
Gets the document object being used by the dom library.
Document
}
.getDocumentHeight()
Calculates the height of the document.
number
}
.getDocumentScroll()
Gets the document scroll distance as a coordinate object.
goog.math.Coordinate
}
.getDocumentScrollElement()
Gets the document scroll element.
Element
}
.getDomHelper(opt_element)
Gets the DomHelper object for the document where the element resides.
opt_element
{(Node
|Window
)=}
goog.dom.DomHelper
}
.getElement(element)
Alias for getElementById. If a DOM node is passed in then we just return that.
element
{string
|Element
}
Element
}
.getElementByClass(className, opt_el)
Returns the first element with the provided className.
className
{string
}
opt_el
{Element
|Document
=}
Element
}
.getElementsByClass(className, opt_el)
Returns an array of all the elements with the provided className.
className
{string
}
opt_el
{(Document
|Element
)=}
length
: number
}}
.getElementsByTagNameAndClass(opt_tag, opt_class, opt_el)
Looks up elements by both tag and class name, using browser native functions ({@code querySelectorAll}, {@code getElementsByTagName} or {@code getElementsByClassName}) where possible. This function is a useful, if limited, way of collecting a list of DOM elements with certain characteristics. {@code 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.
opt_tag
{?string
=}
opt_class
{?string
=}
opt_el
{(Document
|Element
)=}
length
: number
}}
.getFirstElementChild(node)
Returns the first child node that is an element.
node
{Node
}
Element
}
.getFrameContentDocument(frame)
Cross-browser function for getting the document element of a frame or iframe.
frame
{Element
}
Document
}
.getFrameContentWindow(frame)
Cross-browser function for getting the window of a frame or iframe.
frame
{Element
}
Window
}
.getLastElementChild(node)
Returns the last child node that is an element.
node
{Node
}
Element
}
.getNextElementSibling(node)
Returns the first next sibling that is an element.
node
{Node
}
Element
}
.getNextNode(node)
Returns the next node in source order from the given node.
node
{Node
}
Node
}
.getNodeAtOffset(parent, offset, 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.
parent
{Node
}
offset
{number
}
opt_result
{Object
=}
Node
}
.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.
node
{Node
}
number
}
.getNodeTextOffset(node, 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.
node
{Node
}
opt_offsetParent
{Node
=}
number
}
.getOuterHtml(element)
Gets the outerHTML of a node, which islike innerHTML, except that it actually contains the HTML of the node itself.
element
{Element
}
string
}
.getOwnerDocument(node)
Returns the owner document for a node.
node
{Node
|Window
}
Document
}
.getPageScroll(opt_window)
[deprecated]Deprecated. Use {@link goog.dom.getDocumentScroll} instead.
Gets the page scroll distance as a coordinate object.
opt_window
{Window
=}
goog.math.Coordinate
}
.getParentElement(element)
Returns an element's parent, if it's an Element.
element
{Element
}
Element
}
.getPreviousElementSibling(node)
Returns the first previous sibling that is an element.
node
{Node
}
Element
}
.getPreviousNode(node)
Returns the previous node in source order from the given node.
node
{Node
}
Node
}
.getRawTextContent(node)
Returns the text content of the current node, without markup. Unlike {@code getTextContent} this method does not collapse whitespaces or normalize lines breaks.
node
{Node
}
string
}
.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.
node
{Node
}
string
}
.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.
opt_window
{Window
=}
goog.math.Size
}
.getWindow(opt_doc)
Gets the window object associated with the given document.
opt_doc
{Document
=}
Window
}
.htmlToDocumentFragment(htmlString)
Converts an HTML string into a document fragment. The string must be sanitized in order to avoid cross-site scripting. For example {@code goog.dom.htmlToDocumentFragment('<img src=x onerror=alert(0)>')} triggers an alert in all browsers, even if the returned document fragment is thrown away immediately.
htmlString
{string
}
Node
}
goog.dom.iframe
Namespace.insertChildAt(parent, child, index)
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.
parent
{Element
}
child
{Node
}
index
{number
}
.insertSiblingAfter(newNode, 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.
newNode
{Node
}
refNode
{Node
}
.insertSiblingBefore(newNode, 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.
newNode
{Node
}
refNode
{Node
}
.isCss1CompatMode()
Returns true if the browser is in "CSS1-compatible" (standards-compliant) mode, false otherwise.
boolean
}
.isElement(obj)
Whether the object looks like an Element.
obj
{*}
boolean
}
.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.
element
{Element
}
boolean
}
.isNodeLike(obj)
Whether the object looks like a DOM node.
obj
{*}
boolean
}
.isNodeList(val)
Returns true if the object is a {@code 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).
val
{Object
}
boolean
}
.isWindow(obj)
Returns true if the specified value is a Window object. This includes the global window for HTML pages, and iframe windows.
obj
{*}
boolean
}
goog.dom.iter
Namespacegoog.dom.pattern
Namespace.query
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)");query
{string
|Array
}
opt_root
{(string
|Node
)=}
length
: number
}}
.removeChildren(node)
Removes all the child nodes on a DOM node.
node
{Node
}
.removeNode(node)
Removes a node from its parent.
node
{Node
}
Node
}
.replaceNode(newNode, oldNode)
Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no parent.
newNode
{Node
}
oldNode
{Node
}
goog.dom.selection
Namespace.setFocusableTabIndex(element, enable)
Enables or disables keyboard focus support on the element via its tab index. Only elements for which {@link 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.
element
{Element
}
enable
{boolean
}
.setProperties(element, properties)
Sets multiple properties on a node.
element
{Element
}
properties
{Object
}
.setTextContent(element, text)
Cross-browser function for setting the text content of an element.
element
{Element
}
text
{string
}
goog.dom.xml
Namespace