Class goog.dom.DomHelper
code »Create an instance of a DOM helper with a new document object.
Constructor
| Parameters |
|---|
|
Instance Methods
Deprecated: Use DomHelper getElementsByTagNameAndClass.Alias for getElementsByTagNameAndClass.
getElementsByTagNameAndClass.Deprecated: Use goog.dom.DomHelper.prototype.createDom instead.Alias for createDom.
goog.dom.DomHelper.prototype.createDom instead.createDom.| Parameters |
|---|
|
| Returns |
|
Appends a node with text or other nodes.
| Parameters |
|---|
|
code »appendChild ( parent, child )Appends a child to a node.
code »canHaveChildren ( node ) ⇒ booleanDetermines if the given node can contain children, intended to be used for
HTML generation.
boolean| Parameters |
|---|
|
| Returns |
|
code »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.
numberReturns 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
An easy way to move all child nodes of an existing element to a new parent
element is:
createDom('div', null, oldElement.childNodes);
which will remove all child nodes from the old element and add them as
child nodes of the new DIV.
createDom('div', null, createDom('p'), createDom('p'));
would return a div with two child paragraphs
An easy way to move all child nodes of an existing element to a new parent
element is:
createDom('div', null, oldElement.childNodes);
which will remove all child nodes from the old element and add them as
child nodes of the new DIV.| Parameters |
|---|
|
| Returns |
|
code »createElement ( name ) ⇒ !ElementCreates a new element.
!Element| Parameters |
|---|
|
| Returns |
|
code »createTable ( rows, columns, opt_fillWithNbsp ) ⇒ !ElementCreate a table.
!Elementcode »createTextNode ( content ) ⇒ !TextCreates a new text node.
!Textcode »findCommonAncestor ( var_args ) ⇒ NodeFind the deepest common ancestor of the given nodes.
Node| Parameters |
|---|
|
| Returns |
|
code »flattenElement ( element ) ⇒ (Element|undefined)Flattens an element. That is, removes it and replace it with its children.
(Element|undefined)| Parameters |
|---|
|
| Returns |
|
code »getActiveElement ( opt_doc ) ⇒ ElementDetermines the active element in the given document.
Element| Parameters |
|---|
|
| Returns |
|
code »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 »getAncestorByClass ( element, class ) ⇒ 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 »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 »getChildren ( element ) ⇒ !(Array|NodeList)Returns an array containing just the element children of the given element.
!(Array|NodeList)| Parameters |
|---|
|
| Returns |
|
code »getDocument ( ) ⇒ !DocumentGets the document object being used by the dom library.
!Document| Returns |
|---|
|
Calculates the height of the document.
| Returns |
|---|
|
Gets the document scroll distance as a coordinate object.
| Returns |
|---|
|
Gets the document scroll element.
| Returns |
|---|
|
code »getDomHelper ( opt_node ) ⇒ !goog.dom.DomHelperGets the dom helper object for the document where the element resides.
!goog.dom.DomHelper| Parameters |
|---|
|
| Returns |
|
code »getElement ( element ) ⇒ ElementAlias for getElementById. If a DOM node is passed in then we just
return that.
ElementgetElementById. If a DOM node is passed in then we just
return that.code »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. The returned array is a live
NodeList or a static list depending on the code path taken.
{length: number}querySelectorAll, getElementsByTagName or
getElementsByClassName) where possible. The returned array is a live
NodeList or a static list depending on the code path taken.code »getFirstElementChild ( node ) ⇒ ElementReturns the first child node that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is an element. |
code »getFrameContentDocument ( iframe ) ⇒ !DocumentCross browser function for getting the document element of an iframe.
!Document| Parameters |
|---|
|
| Returns |
|
code »getFrameContentWindow ( frame ) ⇒ WindowCross browser function for getting the window of a frame or iframe.
Window| Parameters |
|---|
|
| Returns |
|
code »getLastElementChild ( node ) ⇒ ElementReturns the last child node that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is an element. |
code »getNextElementSibling ( node ) ⇒ ElementReturns the first next sibling that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is an element. |
code »getNextNode ( node ) ⇒ NodeReturns the next node in source order from the given node.
Node| Parameters |
|---|
|
| Returns |
|
code »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 »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 »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.
numbergoog.dom.getNodeTextLength.code »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 »getOwnerDocument ( node ) ⇒ !DocumentReturns the owner document for a node.
!Document| Parameters |
|---|
|
| Returns |
|
code »getParentElement ( element ) ⇒ ElementReturns an element's parent, if it's an Element.
Element| Parameters |
|---|
|
| Returns |
|
code »getPreviousElementSibling ( node ) ⇒ ElementReturns the first previous sibling that is an element.
Element| Parameters |
|---|
|
| Returns |
node that is
an element. |
code »getPreviousNode ( node ) ⇒ NodeReturns the previous node in source order from the given node.
Node| Parameters |
|---|
|
| Returns |
|
code »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 »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 »getTextContent ( node ) ⇒ stringReturns the text contents of the current node, without markup. 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 »getViewportSize ( opt_window ) ⇒ !goog.math.SizeGets the dimensions of the viewport.
!goog.math.Size| Parameters |
|---|
|
| Returns |
|
code »htmlToDocumentFragment ( htmlString ) ⇒ !NodeConverts an HTML string into a node or a document fragment. A single Node
is used if the htmlString only generates a single node. If the
htmlString generates multiple nodes then these are put inside a
DocumentFragment.
!NodehtmlString only generates a single node. If the
htmlString generates multiple nodes then these are put inside a
DocumentFragment.| Parameters |
|---|
|
| Returns |
|
code »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 »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 »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 »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 »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 »isNodeLike ( obj ) ⇒ booleanWhether the object looks like a DOM node.
boolean| Parameters |
|---|
|
| Returns |
|
code »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 »removeChildren ( node )Removes all the child nodes on a DOM node.
| Parameters |
|---|
|
code »removeNode ( node ) ⇒ NodeRemoves a node from its parent.
Node| Parameters |
|---|
|
| Returns |
|
code »replaceNode ( newNode, oldNode )Replaces a node in the DOM tree. Will do nothing if oldNode has no
parent.
oldNode has no
parent.code »setDocument ( document )Sets the document object.
| Parameters |
|---|
|
code »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.