Namespace goog.dom
code »Classes
|
Enumerations
|
Type Definitions
Global Functions
code »goog.dom.$ ( element ) ⇒ ElementDeprecated: Use goog.dom.getElement instead.Alias for getElement.
Elementgoog.dom.getElement instead.code »goog.dom.$$ ( opt_tag, opt_class, opt_el ) ⇒ {length: number}Deprecated: Use goog.dom.getElementsByTagNameAndClass instead.Alias for getElementsByTagNameAndClass.
{length: number}goog.dom.getElementsByTagNameAndClass instead.getElementsByTagNameAndClass.code »goog.dom.$dom ( tagName, opt_attributes, var_args ) ⇒ !ElementDeprecated: Use goog.dom.createDom instead.Alias for createDom.
!Elementgoog.dom.createDom instead.createDom.| Parameters |
|---|
|
| Returns |
|
code »goog.dom.append ( parent, var_args )Appends a node with text or other nodes.
| Parameters |
|---|
|
code »goog.dom.appendChild ( parent, child )Appends a child to a node.
code »goog.dom.append_ ( doc, parent, args, startIndex )Appends a node with text or other nodes.
code »goog.dom.canHaveChildren ( node ) ⇒ booleanDetermines 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() ?
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.canUseQuerySelector_ ( parent ) ⇒ booleanPrefer the standardized (http://www.w3.org/TR/selectors-api/), native and
fast W3C Selectors API.
booleancode »goog.dom.compareNodeOrder ( node1, node2 ) ⇒ numberCompares 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.
numbercode »goog.dom.compareParentsDescendantNodeIe_ ( textNode, node ) ⇒ numberUtility 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.
numbertextNode's parent is an ancestor of node. If this entry
condition is not met, this function will attempt to reference a null object.code »goog.dom.compareSiblingOrder_ ( node1, node2 ) ⇒ numberUtility function to compare the position of two nodes known to be non-equal
siblings.
numbercode »goog.dom.contains ( parent, descendant ) ⇒ booleanWhether a node contains another node.
booleancode »goog.dom.createDom ( tagName, opt_attributes, var_args ) ⇒ !ElementReturns 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
!ElementcreateDom('div', null, createDom('p'), createDom('p'));
would return a div with two child paragraphs| Parameters |
|---|
|
| Returns |
|
code »goog.dom.createDom_ ( doc, args ) ⇒ !ElementHelper for createDom.
!ElementcreateDom.code »goog.dom.createElement ( name ) ⇒ !ElementCreates a new element.
!Element| Parameters |
|---|
|
| Returns |
|
code »goog.dom.createTable ( rows, columns, opt_fillWithNbsp ) ⇒ !ElementCreate a table.
!Elementcode »goog.dom.createTable_ ( doc, rows, columns, fillWithNbsp ) ⇒ !ElementCreate a table.
!Elementcode »goog.dom.createTextNode ( content ) ⇒ !TextCreates a new text node.
!Textcode »goog.dom.findCommonAncestor ( var_args ) ⇒ NodeFind the deepest common ancestor of the given nodes.
Node| Parameters |
|---|
|
| Returns |
|
code »goog.dom.findNode ( root, 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.
(Node|undefined)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.code »goog.dom.findNodes ( root, p ) ⇒ !ArrayFinds 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.
!Arraygoog.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.code »goog.dom.findNodes_ ( root, p, rv, findOne ) ⇒ booleanFinds the first or all the descendant nodes that match the filter function,
using a depth first search.
boolean| Parameters |
|---|
| Returns |
|
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.
(Element|undefined)| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getActiveElement ( doc ) ⇒ ElementDetermines the active element in the given document.
Element| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getAncestor ( element, matcher, opt_includeNode, opt_maxSearchSteps ) ⇒ NodeWalks up the DOM hierarchy returning the first ancestor that passes the
matcher function.
Node| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getAncestorByClass ( element, className ) ⇒ ElementWalks 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.
Elementcode »goog.dom.getAncestorByTagNameAndClass ( element, opt_tag, opt_class ) ⇒ ElementWalks 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| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getChildren ( element ) ⇒ !(Array|NodeList)Returns an array containing just the element children of the given element.
!(Array|NodeList)| Parameters |
|---|
|
| Returns |
|
Gets the document object being used by the dom library.
| Returns |
|---|
|
Calculates the height of the document.
| Returns |
|---|
|
code »goog.dom.getDocumentHeight_ ( win ) ⇒ numberCalculates the height of the document of the given window.
Function code copied from the opensocial gadget api:
gadgets.window.adjustHeight(opt_height)
number| Parameters |
|---|
|
| Returns |
|
Gets the document scroll distance as a coordinate object.
| Returns |
|---|
|
Gets the document scroll element.
| Returns |
|---|
|
code »goog.dom.getDocumentScrollElement_ ( doc ) ⇒ !ElementHelper for getDocumentScrollElement.
!ElementgetDocumentScrollElement.| Parameters |
|---|
|
| Returns |
|
Helper for getDocumentScroll.
getDocumentScroll.| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getDomHelper ( opt_element ) ⇒ !goog.dom.DomHelperGets the DomHelper object for the document where the element resides.
!goog.dom.DomHelper| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getElement ( element ) ⇒ ElementGets an element from the current document by element id.
If an Element is passed in, it is returned.
Elementcode »goog.dom.getElementHelper_ ( doc, element ) ⇒ ElementGets an element by id from the given document (if present).
If an element is given, it is returned.
Elementcode »goog.dom.getElementsByClass ( className, opt_el ) ⇒ {length: number}Returns a static, array-like list of the elements with the provided
className.
{length: number}code »goog.dom.getElementsByTagNameAndClass ( opt_tag, opt_class, 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.
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
{length: number}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=83438code »goog.dom.getElementsByTagNameAndClass_ ( doc, opt_tag, opt_class, opt_el ) ⇒ {length: number}Helper for getElementsByTagNameAndClass.
{length: number}getElementsByTagNameAndClass.code »goog.dom.getFirstElementChild ( node ) ⇒ ElementReturns the first child node that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is an element. |
code »goog.dom.getFrameContentDocument ( frame ) ⇒ !DocumentCross-browser function for getting the document element of a frame or iframe.
!Document| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getFrameContentWindow ( frame ) ⇒ WindowCross-browser function for getting the window of a frame or iframe.
Window| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getLastElementChild ( node ) ⇒ ElementReturns the last child node that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is an element. |
code »goog.dom.getNextElementNode_ ( node, forward ) ⇒ ElementReturns the first node that is an element in the specified direction,
starting with node.
Elementnode.code »goog.dom.getNextElementSibling ( node ) ⇒ ElementReturns the first next sibling that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is an element. |
code »goog.dom.getNextNode ( node ) ⇒ NodeReturns the next node in source order from the given node.
Node| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getNodeAtOffset ( parent, offset, opt_result ) ⇒ NodeReturns 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.
Nodecode »goog.dom.getNodeTextLength ( node ) ⇒ numberReturns 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.
number| Parameters |
|---|
|
| Returns |
node's text content. |
code »goog.dom.getNodeTextOffset ( node, opt_offsetParent ) ⇒ numberReturns 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.
numbercode »goog.dom.getOuterHtml ( element ) ⇒ stringGets the outerHTML of a node, which islike innerHTML, except that it
actually contains the HTML of the node itself.
string| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getOwnerDocument ( node ) ⇒ !DocumentReturns the owner document for a node.
!Document| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getPageScroll ( opt_window ) ⇒ !goog.math.CoordinateDeprecated: Use goog.dom.getDocumentScroll instead.Gets the page scroll distance as a coordinate object.
!goog.math.Coordinategoog.dom.getDocumentScroll instead.| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getParentElement ( element ) ⇒ ElementReturns an element's parent, if it's an Element.
Element| Parameters |
|---|
|
| Returns |
|
Gives the current devicePixelRatio.
By default, this is the value of window.devicePixelRatio (which should be
preferred if present).
If window.devicePixelRatio is not present, the ratio is calculated with
window.matchMedia, if present. Otherwise, gives 1.0.
Some browsers (including Chrome) consider the browser zoom level in the pixel
ratio, so the value may change across multiple calls.
| Returns |
|---|
|
code »goog.dom.getPreviousElementSibling ( node ) ⇒ ElementReturns the first previous sibling that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is
an element. |
code »goog.dom.getPreviousNode ( node ) ⇒ NodeReturns the previous node in source order from the given node.
Node| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getRawTextContent ( node ) ⇒ stringReturns the text content of the current node, without markup.
Unlike getTextContent this method does not collapse whitespaces
or normalize lines breaks.
stringgetTextContent this method does not collapse whitespaces
or normalize lines breaks.| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getRequiredElement ( id ) ⇒ !ElementGets 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).
!Element| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getRequiredElementByClass ( className, opt_root ) ⇒ !ElementEnsures an element with the given className exists, and then returns the
first element with the provided className.
!Element| Parameters |
|---|
| Returns |
|
| Throws |
|
code »goog.dom.getRequiredElementHelper_ ( doc, id ) ⇒ !ElementHelper function for getRequiredElementHelper functions, both static and
on DomHelper. Asserts the element with the given id exists.
!Element| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getTextContent ( node ) ⇒ stringReturns 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.
string| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getTextContent_ ( node, buf, normalizeWhitespace )Recursive support function for text content retrieval.
code »goog.dom.getViewportSize ( opt_window ) ⇒ !goog.math.SizeGets 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.
!goog.math.Size| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getViewportSize_ ( win ) ⇒ !goog.math.SizeHelper for getViewportSize.
!goog.math.SizegetViewportSize.| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getWindow ( opt_doc ) ⇒ !WindowGets the window object associated with the given document.
!Window| Parameters |
|---|
|
| Returns |
|
code »goog.dom.getWindow_ ( doc ) ⇒ !WindowHelper for getWindow.
!WindowgetWindow.| Parameters |
|---|
|
| Returns |
|
code »goog.dom.hasNonZeroBoundingRect_ ( element ) ⇒ booleanReturns true if the element has a bounding rectangle that would be visible
(i.e. its width and height are greater than zero).
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.hasSpecifiedTabIndex_ ( element ) ⇒ booleanReturns true if the element has a specified tab index.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.htmlToDocumentFragment ( htmlString ) ⇒ !NodeConverts an HTML string into a document fragment. The string must be
sanitized in order to avoid cross-site scripting. For example
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.
!Nodegoog.dom.htmlToDocumentFragment('<img src=x onerror=alert(0)>')
triggers an alert in all browsers, even if the returned document fragment
is thrown away immediately.| Parameters |
|---|
|
| Returns |
|
code »goog.dom.htmlToDocumentFragment_ ( doc, htmlString ) ⇒ !NodeHelper for htmlToDocumentFragment.
!NodehtmlToDocumentFragment.code »goog.dom.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.
code »goog.dom.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.
code »goog.dom.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.
Returns true if the browser is in "CSS1-compatible" (standards-compliant)
mode, false otherwise.
| Returns |
|---|
|
code »goog.dom.isCss1CompatMode_ ( doc ) ⇒ booleanReturns true if the browser is in "CSS1-compatible" (standards-compliant)
mode, false otherwise.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.isElement ( obj ) ⇒ booleanWhether the object looks like an Element.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.isFocusable ( element ) ⇒ booleanReturns 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.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.isFocusableTabIndex ( element ) ⇒ booleanReturns 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.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.isNodeLike ( obj ) ⇒ booleanWhether the object looks like a DOM node.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.isNodeList ( val ) ⇒ booleanReturns 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).
booleanNodeList. 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).| Parameters |
|---|
|
| Returns |
|
code »goog.dom.isTabIndexFocusable_ ( element ) ⇒ booleanReturns true if the element's tab index allows the element to be focused.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.isWindow ( obj ) ⇒ booleanReturns true if the specified value is a Window object. This includes the
global window for HTML pages, and iframe windows.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.matchesPixelRatio_ ( pixelRatio ) ⇒ numberCalculates a mediaQuery to check if the current device supports the
given actual to virtual pixel ratio.
number| Parameters |
|---|
|
| Returns |
|
code »goog.dom.nativelySupportsFocus_ ( element ) ⇒ booleanReturns true if the element is focusable even when tabIndex is not set.
boolean| Parameters |
|---|
|
| Returns |
|
code »goog.dom.removeChildren ( node )Removes all the child nodes on a DOM node.
| Parameters |
|---|
|
code »goog.dom.removeNode ( node ) ⇒ NodeRemoves a node from its parent.
Node| Parameters |
|---|
|
| Returns |
|
code »goog.dom.replaceNode ( newNode, oldNode )Replaces a node in the DOM tree. Will do nothing if oldNode has no
parent.
oldNode has no
parent.code »goog.dom.setFocusableTabIndex ( element, 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.
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.