Namespace goog.dom
code »Classes
|
Enumerations
|
Type Definitions
Global Functions
code »goog.dom.$ ( element ) ⇒ Element
Deprecated: Use goog.dom.getElement
instead.Alias for getElement.
Element
goog.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 ) ⇒ !Element
Deprecated: Use goog.dom.createDom
instead.Alias for createDom
.
!Element
goog.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 ) ⇒ 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() ?
boolean
Parameters |
---|
|
Returns |
|
code »goog.dom.canUseQuerySelector_ ( parent ) ⇒ boolean
Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and
fast W3C Selectors API.
boolean
code »goog.dom.compareNodeOrder ( node1, node2 ) ⇒ 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.
number
code »goog.dom.compareParentsDescendantNodeIe_ ( textNode, node ) ⇒ 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.
number
textNode
'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 ) ⇒ number
Utility function to compare the position of two nodes known to be non-equal
siblings.
number
code »goog.dom.contains ( parent, descendant ) ⇒ boolean
Whether a node contains another node.
boolean
code »goog.dom.createDom ( tagName, opt_attributes, var_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
!Element
createDom('div', null, createDom('p'), createDom('p'));
would return a div with two child paragraphsParameters |
---|
|
Returns |
|
code »goog.dom.createDom_ ( doc, args ) ⇒ !Element
Helper for createDom
.
!Element
createDom
.code »goog.dom.createElement ( name ) ⇒ !Element
Creates a new element.
!Element
Parameters |
---|
|
Returns |
|
code »goog.dom.createTable ( rows, columns, opt_fillWithNbsp ) ⇒ !Element
Create a table.
!Element
code »goog.dom.createTable_ ( doc, rows, columns, fillWithNbsp ) ⇒ !Element
Create a table.
!Element
code »goog.dom.createTextNode ( content ) ⇒ !Text
Creates a new text node.
!Text
code »goog.dom.findCommonAncestor ( var_args ) ⇒ Node
Find 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 ) ⇒ !Array
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.
!Array
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, rv, findOne ) ⇒ boolean
Finds 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 ) ⇒ Element
Determines the active element in the given document.
Element
Parameters |
---|
|
Returns |
|
code »goog.dom.getAncestor ( element, matcher, opt_includeNode, opt_maxSearchSteps ) ⇒ Node
Walks up the DOM hierarchy returning the first ancestor that passes the
matcher function.
Node
Parameters |
---|
|
Returns |
|
code »goog.dom.getAncestorByClass ( element, className ) ⇒ 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.
Element
code »goog.dom.getAncestorByTagNameAndClass ( element, opt_tag, opt_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.
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 ) ⇒ number
Calculates 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 ) ⇒ !Element
Helper for getDocumentScrollElement
.
!Element
getDocumentScrollElement
.Parameters |
---|
|
Returns |
|
Helper for getDocumentScroll
.
getDocumentScroll
.Parameters |
---|
|
Returns |
|
code »goog.dom.getDomHelper ( opt_element ) ⇒ !goog.dom.DomHelper
Gets the DomHelper object for the document where the element resides.
!goog.dom.DomHelper
Parameters |
---|
|
Returns |
|
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.
Element
code »goog.dom.getElementHelper_ ( doc, element ) ⇒ Element
Gets an element by id from the given document (if present).
If an element is given, it is returned.
Element
code »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 ) ⇒ Element
Returns the first child node that is an element.
Element
Parameters |
---|
|
Returns |
node that is an element. |
code »goog.dom.getFrameContentDocument ( frame ) ⇒ !Document
Cross-browser function for getting the document element of a frame or iframe.
!Document
Parameters |
---|
|
Returns |
|
code »goog.dom.getFrameContentWindow ( frame ) ⇒ Window
Cross-browser function for getting the window of a frame or iframe.
Window
Parameters |
---|
|
Returns |
|
code »goog.dom.getLastElementChild ( node ) ⇒ Element
Returns the last child node that is an element.
Element
Parameters |
---|
|
Returns |
node that is an element. |
code »goog.dom.getNextElementNode_ ( node, forward ) ⇒ Element
Returns the first node that is an element in the specified direction,
starting with node
.
Element
node
.code »goog.dom.getNextElementSibling ( node ) ⇒ Element
Returns the first next sibling that is an element.
Element
Parameters |
---|
|
Returns |
node that is an element. |
code »goog.dom.getNextNode ( node ) ⇒ Node
Returns the next node in source order from the given node.
Node
Parameters |
---|
|
Returns |
|
code »goog.dom.getNodeAtOffset ( parent, offset, opt_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.
Node
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.
number
Parameters |
---|
|
Returns |
node 's text content. |
code »goog.dom.getNodeTextOffset ( node, opt_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.
number
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.
string
Parameters |
---|
|
Returns |
|
code »goog.dom.getOwnerDocument ( node ) ⇒ !Document
Returns the owner document for a node.
!Document
Parameters |
---|
|
Returns |
|
code »goog.dom.getPageScroll ( opt_window ) ⇒ !goog.math.Coordinate
Deprecated: Use goog.dom.getDocumentScroll
instead.Gets the page scroll distance as a coordinate object.
!goog.math.Coordinate
goog.dom.getDocumentScroll
instead.Parameters |
---|
|
Returns |
|
code »goog.dom.getParentElement ( element ) ⇒ Element
Returns 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 ) ⇒ Element
Returns the first previous sibling that is an element.
Element
Parameters |
---|
|
Returns |
node that is
an element. |
code »goog.dom.getPreviousNode ( node ) ⇒ Node
Returns the previous node in source order from the given node.
Node
Parameters |
---|
|
Returns |
|
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.
string
getTextContent
this method does not collapse whitespaces
or normalize lines breaks.Parameters |
---|
|
Returns |
|
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).
!Element
Parameters |
---|
|
Returns |
|
code »goog.dom.getRequiredElementByClass ( className, opt_root ) ⇒ !Element
Ensures 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 ) ⇒ !Element
Helper 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 ) ⇒ 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.
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.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.
!goog.math.Size
Parameters |
---|
|
Returns |
|
code »goog.dom.getViewportSize_ ( win ) ⇒ !goog.math.Size
Helper for getViewportSize
.
!goog.math.Size
getViewportSize
.Parameters |
---|
|
Returns |
|
code »goog.dom.getWindow ( opt_doc ) ⇒ !Window
Gets the window object associated with the given document.
!Window
Parameters |
---|
|
Returns |
|
code »goog.dom.getWindow_ ( doc ) ⇒ !Window
Helper for getWindow
.
!Window
getWindow
.Parameters |
---|
|
Returns |
|
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).
boolean
Parameters |
---|
|
Returns |
|
code »goog.dom.hasSpecifiedTabIndex_ ( element ) ⇒ boolean
Returns true if the element has a specified tab index.
boolean
Parameters |
---|
|
Returns |
|
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('<img src=x onerror=alert(0)>')
triggers an alert in all browsers, even if the returned document fragment
is thrown away immediately.
!Node
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.Parameters |
---|
|
Returns |
|
code »goog.dom.htmlToDocumentFragment_ ( doc, htmlString ) ⇒ !Node
Helper for htmlToDocumentFragment
.
!Node
htmlToDocumentFragment
.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 ) ⇒ boolean
Returns true if the browser is in "CSS1-compatible" (standards-compliant)
mode, false otherwise.
boolean
Parameters |
---|
|
Returns |
|
code »goog.dom.isElement ( obj ) ⇒ boolean
Whether the object looks like an Element.
boolean
Parameters |
---|
|
Returns |
|
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.
boolean
Parameters |
---|
|
Returns |
|
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.
boolean
Parameters |
---|
|
Returns |
|
code »goog.dom.isNodeLike ( obj ) ⇒ boolean
Whether the object looks like a DOM node.
boolean
Parameters |
---|
|
Returns |
|
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).
boolean
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).Parameters |
---|
|
Returns |
|
code »goog.dom.isTabIndexFocusable_ ( element ) ⇒ boolean
Returns true if the element's tab index allows the element to be focused.
boolean
Parameters |
---|
|
Returns |
|
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.
boolean
Parameters |
---|
|
Returns |
|
code »goog.dom.matchesPixelRatio_ ( pixelRatio ) ⇒ number
Calculates a mediaQuery to check if the current device supports the
given actual to virtual pixel ratio.
number
Parameters |
---|
|
Returns |
|
code »goog.dom.nativelySupportsFocus_ ( element ) ⇒ boolean
Returns 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 ) ⇒ Node
Removes 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.