Package com.google.gwt.dom.client
Class Node
java.lang.Object
com.google.gwt.core.client.JavaScriptObject
com.google.gwt.dom.client.Node
The Node interface is the primary datatype for the entire Document Object
Model. It represents a single node in the document tree. While all objects
implementing the Node interface expose methods for dealing with children, not
all objects implementing the Node interface may have children.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal <T extends Node>
TappendChild
(T newChild) Adds the node newChild to the end of the list of children of this node.static Node
Assert that the givenJavaScriptObject
is a DOM node and automatically typecast it.final Node
cloneNode
(boolean deep) Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.final Node
getChild
(int index) Gets the child node at the given index.final int
Gets the number of child nodes contained within this node.A NodeList that contains all children of this node.final Node
The first child of this node.final Node
The last child of this node.final Node
The node immediately following this node.final String
The name of this node, depending on its type; see the table above.final short
A code representing the type of the underlying object, as defined above.final String
The value of this node, depending on its type; see the table above.final Document
The Document object associated with this node.final Element
Gets the parent element of this node.final Node
The parent of this node.final Node
The node immediately preceding this node.final boolean
Returns whether this node has any children.final boolean
Determines whether this node has a parent element.final Node
insertAfter
(Node newChild, Node refChild) Inserts the node newChild after the existing child node refChild.final Node
insertBefore
(Node newChild, Node refChild) Inserts the node newChild before the existing child node refChild.final Node
insertFirst
(Node child) Inserts the given child as the first child of this node.static boolean
Determines whether the givenJavaScriptObject
is a DOM node.final boolean
isOrHasChild
(Node child) Determine whether a node is equal to, or the child of, this node.final Node
Remove all children of the node.final Node
removeChild
(Node oldChild) Removes the child node indicated by oldChild from the list of children, and returns it.final void
Removes this node from its parent node if it is attached to one.final Node
replaceChild
(Node newChild, Node oldChild) Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.final void
setNodeValue
(String nodeValue) The value of this node, depending on its type; see the table above.Methods inherited from class com.google.gwt.core.client.JavaScriptObject
cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString
-
Field Details
-
Constructor Details
-
Node
protected Node()
-
-
Method Details
-
as
Assert that the givenJavaScriptObject
is a DOM node and automatically typecast it. -
is
Determines whether the givenJavaScriptObject
is a DOM node. Anull
object will cause this method to returnfalse
. The try catch is needed for the firefox permission error: "Permission denied to access property 'nodeType'" -
appendChild
Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.- Parameters:
newChild
- The node to add- Returns:
- The node added
-
cloneNode
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent; (parentNode is null.). Cloning an Element copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a child Text node. Cloning an Attribute directly, as opposed to be cloned as part of an Element cloning operation, returns a specified attribute (specified is true). Cloning any other type of node simply returns a copy of this node.- Parameters:
deep
- If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is anElement
)- Returns:
- The duplicate node
-
getChild
Gets the child node at the given index.- Parameters:
index
- the index of the node to be retrieved- Returns:
- the child node at the given index
-
getChildCount
public final int getChildCount()Gets the number of child nodes contained within this node.- Returns:
- the number of child nodes
-
getChildNodes
A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes. -
getFirstChild
The first child of this node. If there is no such node, this returns null. -
getLastChild
The last child of this node. If there is no such node, this returns null. -
getNextSibling
The node immediately following this node. If there is no such node, this returns null. -
getNodeName
The name of this node, depending on its type; see the table above. -
getNodeType
public final short getNodeType()A code representing the type of the underlying object, as defined above. -
getNodeValue
The value of this node, depending on its type; see the table above. When it is defined to be null, setting it has no effect. -
getOwnerDocument
The Document object associated with this node. This is also theDocument
object used to create new nodes. -
getParentElement
Gets the parent element of this node.- Returns:
- this node's parent element, or
null
if none exists
-
getParentNode
The parent of this node. All nodes except Document may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null. -
getPreviousSibling
The node immediately preceding this node. If there is no such node, this returns null. -
hasChildNodes
public final boolean hasChildNodes()Returns whether this node has any children. -
hasParentElement
public final boolean hasParentElement()Determines whether this node has a parent element.- Returns:
- true if the node has a parent element
-
insertAfter
Inserts the node newChild after the existing child node refChild. If refChild isnull
, insert newChild at the end of the list of children.- Parameters:
newChild
- The node to insertrefChild
- The reference node (that is, the node after which the new node must be inserted), ornull
- Returns:
- The node being inserted
-
insertBefore
Inserts the node newChild before the existing child node refChild. If refChild isnull
, insert newChild at the end of the list of children.- Parameters:
newChild
- The node to insertrefChild
- The reference node (that is, the node before which the new node must be inserted), ornull
- Returns:
- The node being inserted
-
insertFirst
Inserts the given child as the first child of this node.- Parameters:
child
- the child to be inserted- Returns:
- The node being inserted
-
isOrHasChild
Determine whether a node is equal to, or the child of, this node.- Parameters:
child
- the potential child element- Returns:
true
if the relationship holds
-
removeChild
Removes the child node indicated by oldChild from the list of children, and returns it.- Parameters:
oldChild
- The node being removed- Returns:
- The node removed
-
removeAllChildren
Remove all children of the node. -
removeFromParent
public final void removeFromParent()Removes this node from its parent node if it is attached to one. -
replaceChild
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.- Parameters:
newChild
- The new node to put in the child listoldChild
- The node being replaced in the list- Returns:
- The node replaced
-
setNodeValue
The value of this node, depending on its type; see the table above. When it is defined to be null, setting it has no effect.
-