Package org.htmlunit.javascript.host.dom
Class Node
java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.event.EventTarget
org.htmlunit.javascript.host.dom.Node
- All Implemented Interfaces:
Serializable
,Cloneable
,org.htmlunit.corejs.javascript.ConstProperties
,org.htmlunit.corejs.javascript.debug.DebuggableObject
,org.htmlunit.corejs.javascript.Scriptable
,org.htmlunit.corejs.javascript.SymbolScriptable
- Direct Known Subclasses:
Attr
,CharacterData
,Document
,DocumentFragment
,DocumentType
,Element
The JavaScript object
Node
which is the base class for all DOM
objects. This will typically wrap an instance of DomNode
.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
private NodeList
"Live" child nodes collection; has to be a member to have equality (==) working.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
after
(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode.protected static void
append
(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node objects or string objects after the last child of the Element.appendChild
(Object childObject) Adds a DOM node to the node.protected static void
before
(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode.cloneNode
(boolean deep) Clones this node.int
Compares the positions of this node and the provided node within the document.boolean
Checks whether the given element is contained within this object.Returns the attributes of this XML element.Returns the Base URI as a string.protected int
Returns the current number of child elements.Returns the child nodes of the current element.protected HTMLCollection
Gets the children of the current node.Gets the JavaScript propertyfirstChild
for the node that contains the current node.protected Element
Returns the first element child.protected Node
getJavaScriptNode
(DomNode domNode) Gets the JavaScript node for a given DomNode.Gets the JavaScript propertylastChild
for the node that contains the current node.protected Element
Returns the last element child.Returns the local name of this attribute.Returns the URI that identifies an XML namespace.Gets the JavaScript propertynextSibling
for the node that contains the current node.Gets the JavaScript propertynodeName
for the current node.int
Gets the JavaScript propertynodeType
for the current node.Gets the JavaScript propertynodeValue
for the current node.Returns the owner document.final Node
Returns this node's parent node.Gets the JavaScript propertyparentElement
.Gets the JavaScript propertyparentNode
for the node that contains the current node.Returns the namespace prefix.Gets the JavaScript propertypreviousSibling
for the node that contains the current node.Returns the owner document.Gets the textContent attribute.boolean
Returns true when the current element has any attributes or not.boolean
Returns whether this node has any children.private static void
initInlineFrameIfNeeded
(DomNode childDomNode) If we have added a new iframe that had no source attribute, we have to take care the 'onload' handler is triggered.static Object
insertBefore
(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Add a DOM node as a child to this node before the referenced node.protected Object
insertBeforeImpl
(Object[] args) Add a DOM node as a child to this node before the referenced node.boolean
isEqualNode
(Node other) Check if 2 nodes are equals.private static boolean
isNodeInsertable
(Node childObject) Indicates if the node can be inserted.boolean
isSameNode
(Object other) This method provides a way to determine whether two Node references returned by the implementation reference the same object.void
JavaScript constructor.void
Merges adjacent TextNode objects to produce a normalized document object model.protected static void
prepend
(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node objects or string objects before the first child of the Element.protected void
remove()
Removes the DOM node from its parent.removeChild
(Object childObject) Removes a DOM node from this node.replaceChild
(Object newChildObject, Object oldChildObject) Replaces a child DOM node with another DOM node.protected static void
replaceChildren
(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Replaces the existing children of a Node with a specified new set of children.protected static void
replaceWith
(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Replaces this ChildNode in the children list of its parent with a set of Node or DOMString objects.void
setNodeValue
(String newValue) Sets the JavaScript propertynodeValue
for the current node.void
setTextContent
(Object value) Replace all children elements of this element with the supplied value.private static Node
toNodeOrTextNode
(Node thisObj, Object obj) Methods inherited from class org.htmlunit.javascript.host.event.EventTarget
addEventListener, clearEventListenersContainer, dispatchEvent, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, removeEventListener, setEventHandler
Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromise
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
Field Details
-
ELEMENT_NODE
public static final int ELEMENT_NODE- See Also:
-
ATTRIBUTE_NODE
public static final int ATTRIBUTE_NODE- See Also:
-
TEXT_NODE
public static final int TEXT_NODE- See Also:
-
CDATA_SECTION_NODE
public static final int CDATA_SECTION_NODE- See Also:
-
ENTITY_REFERENCE_NODE
public static final int ENTITY_REFERENCE_NODE- See Also:
-
ENTITY_NODE
public static final int ENTITY_NODE- See Also:
-
PROCESSING_INSTRUCTION_NODE
public static final int PROCESSING_INSTRUCTION_NODE- See Also:
-
COMMENT_NODE
public static final int COMMENT_NODE- See Also:
-
DOCUMENT_NODE
public static final int DOCUMENT_NODE- See Also:
-
DOCUMENT_TYPE_NODE
public static final int DOCUMENT_TYPE_NODE- See Also:
-
DOCUMENT_FRAGMENT_NODE
public static final int DOCUMENT_FRAGMENT_NODE- See Also:
-
NOTATION_NODE
public static final int NOTATION_NODE- See Also:
-
DOCUMENT_POSITION_DISCONNECTED
public static final int DOCUMENT_POSITION_DISCONNECTED- See Also:
-
DOCUMENT_POSITION_PRECEDING
public static final int DOCUMENT_POSITION_PRECEDING- See Also:
-
DOCUMENT_POSITION_FOLLOWING
public static final int DOCUMENT_POSITION_FOLLOWING- See Also:
-
DOCUMENT_POSITION_CONTAINS
public static final int DOCUMENT_POSITION_CONTAINS- See Also:
-
DOCUMENT_POSITION_CONTAINED_BY
public static final int DOCUMENT_POSITION_CONTAINED_BY- See Also:
-
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
public static final int DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC- See Also:
-
childNodes_
"Live" child nodes collection; has to be a member to have equality (==) working.
-
-
Constructor Details
-
Node
public Node()Creates an instance.
-
-
Method Details
-
jsConstructor
public void jsConstructor()JavaScript constructor.- Overrides:
jsConstructor
in classEventTarget
-
getNodeType
public int getNodeType()Gets the JavaScript propertynodeType
for the current node.- Returns:
- the node type
-
getNodeName
Gets the JavaScript propertynodeName
for the current node.- Returns:
- the node name
-
getNodeValue
Gets the JavaScript propertynodeValue
for the current node.- Returns:
- the node value
-
setNodeValue
Sets the JavaScript propertynodeValue
for the current node.- Parameters:
newValue
- the new node value
-
appendChild
Adds a DOM node to the node.- Parameters:
childObject
- the node to add to this node- Returns:
- the newly added child node
-
initInlineFrameIfNeeded
If we have added a new iframe that had no source attribute, we have to take care the 'onload' handler is triggered. -
insertBefore
public static Object insertBefore(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Add a DOM node as a child to this node before the referenced node. If the referenced node is null, append to the end.- Parameters:
context
- the JavaScript contextscope
- the scopethisObj
- the scriptableargs
- the arguments passed into the methodfunction
- the function- Returns:
- the newly added child node
-
insertBeforeImpl
Add a DOM node as a child to this node before the referenced node. If the referenced node is null, append to the end.- Parameters:
args
- the arguments- Returns:
- the newly added child node
-
isNodeInsertable
Indicates if the node can be inserted.- Parameters:
childObject
- the node- Returns:
false
if it is not allowed here
-
remove
protected void remove()Removes the DOM node from its parent.- See Also:
-
removeChild
Removes a DOM node from this node.- Parameters:
childObject
- the node to remove from this node- Returns:
- the removed child node
-
replaceChild
Replaces a child DOM node with another DOM node.- Parameters:
newChildObject
- the node to add as a child of this nodeoldChildObject
- the node to remove as a child of this node- Returns:
- the removed child node
-
cloneNode
Clones this node.- Parameters:
deep
- iftrue
, recursively clones all descendants- Returns:
- the newly cloned node
-
isEqualNode
Check if 2 nodes are equals. For detail specifications- Parameters:
other
- the node to compare with- Returns:
- true or false
- See Also:
-
isSameNode
This method provides a way to determine whether two Node references returned by the implementation reference the same object. When two Node references are references to the same object, even if through a proxy, the references may be used completely interchangeably, such that all attributes have the same values and calling the same DOM method on either reference always has exactly the same effect.- Parameters:
other
- the node to test against- Returns:
- whether this node is the same node as the given one
-
hasChildNodes
public boolean hasChildNodes()Returns whether this node has any children.- Returns:
- boolean true if this node has any children, false otherwise
-
getChildNodes
Returns the child nodes of the current element.- Returns:
- the child nodes of the current element
-
getParent
Returns this node's parent node.- Returns:
- this node's parent node
-
getParentNode
Gets the JavaScript propertyparentNode
for the node that contains the current node.- Returns:
- the parent node
-
getNextSibling
Gets the JavaScript propertynextSibling
for the node that contains the current node.- Returns:
- the next sibling node or null if the current node has no next sibling.
-
getPreviousSibling
Gets the JavaScript propertypreviousSibling
for the node that contains the current node.- Returns:
- the previous sibling node or null if the current node has no previous sibling.
-
getFirstChild
Gets the JavaScript propertyfirstChild
for the node that contains the current node.- Returns:
- the first child node or null if the current node has no children.
-
getLastChild
Gets the JavaScript propertylastChild
for the node that contains the current node.- Returns:
- the last child node or null if the current node has no children.
-
getJavaScriptNode
Gets the JavaScript node for a given DomNode.- Parameters:
domNode
- the DomNode- Returns:
- the JavaScript node or null if the DomNode was null
-
getOwnerDocument
Returns the owner document.- Returns:
- the document
-
getRootNode
Returns the owner document.- Returns:
- the document
-
compareDocumentPosition
Compares the positions of this node and the provided node within the document.- Parameters:
node
- node object that specifies the node to check- Returns:
- how the node is positioned relatively to the reference node.
- See Also:
-
normalize
public void normalize()Merges adjacent TextNode objects to produce a normalized document object model. -
getTextContent
Gets the textContent attribute.- Returns:
- the contents of this node as text
-
setTextContent
Replace all children elements of this element with the supplied value.- Parameters:
value
- - the new value for the contents of this node
-
getParentElement
Gets the JavaScript propertyparentElement
.- Returns:
- the parent element
- See Also:
-
getAttributes
Returns the attributes of this XML element.- Returns:
- the attributes of this XML element
- See Also:
-
contains
Checks whether the given element is contained within this object.- Parameters:
element
- element object that specifies the element to check- Returns:
- true if the element is contained within this object
-
getBaseURI
Returns the Base URI as a string.- Returns:
- the Base URI as a string
-
hasAttributes
public boolean hasAttributes()Returns true when the current element has any attributes or not.- Returns:
- true if an attribute is specified on this element
-
getPrefix
Returns the namespace prefix.- Returns:
- the namespace prefix
-
getLocalName
Returns the local name of this attribute.- Returns:
- the local name of this attribute
-
getNamespaceURI
Returns the URI that identifies an XML namespace.- Returns:
- the URI that identifies an XML namespace
-
getChildElementCount
protected int getChildElementCount()Returns the current number of child elements.- Returns:
- the child element count
-
getFirstElementChild
Returns the first element child.- Returns:
- the first element child
-
getLastElementChild
Returns the last element child.- Returns:
- the last element child
-
getChildren
Gets the children of the current node.- Returns:
- the child at the given position
- See Also:
-
after
protected static void after(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode.- Parameters:
context
- the contextthisObj
- this objectargs
- the argumentsfunction
- the function
-
append
protected static void append(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node objects or string objects after the last child of the Element. String objects are inserted as equivalent Text nodes.- Parameters:
context
- the contextthisObj
- this objectargs
- the argumentsfunction
- the function
-
prepend
protected static void prepend(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node objects or string objects before the first child of the Element. String objects are inserted as equivalent Text nodes.- Parameters:
context
- the contextthisObj
- this objectargs
- the argumentsfunction
- the function
-
replaceChildren
protected static void replaceChildren(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Replaces the existing children of a Node with a specified new set of children. These can be string or Node objects.- Parameters:
context
- the contextthisObj
- this objectargs
- the argumentsfunction
- the function
-
toNodeOrTextNode
-
before
protected static void before(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode.- Parameters:
context
- the contextthisObj
- this objectargs
- the argumentsfunction
- the function
-
replaceWith
protected static void replaceWith(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, org.htmlunit.corejs.javascript.Function function) Replaces this ChildNode in the children list of its parent with a set of Node or DOMString objects.- Parameters:
context
- the contextthisObj
- this objectargs
- the argumentsfunction
- the function
-