Help Center

Local Navigation

Object: Node

Availability

BlackBerry® Device Software version 4.6 or later

Extended by

Attr, CharacterData, Document, DocumentFragment, DocumentType, Element, Entity, EntityReference, Notation, ProcessingInstruction

The Node object represents a unique node within the DOM tree. It is the primary data type for the DOM.

While Node exposes methods for dealing with children, not all objects inheriting from Node may have children. For example, Text nodes do not permit children; trying to add children to such nodes results in a DOMException being raised.

The Node.nodeName, Node.nodeValue, and Node.nodeType properties enable you to acquire node information without casting down to the specific child object. In cases where there is no obvious mapping of these properties for a specific nodeType (for example, the Node.nodeValue for an Element, or attributes for a Comment), they return null.

The specialized objects may contain additional and more convenient mechanisms to get and set the relevant information.

Node properties

Property name

Type

Description

Status

Availability

attributes

NamedNodeMap

Returns a NamedNodeMap object that contains the attributes of the given element node, or null, if the node is not an element.

read only

4.6 or later

childNodes

NodeList

Returns a NodeList object that contains all the child elements of the given node.

read only

4.6 or later

firstChild

Node

Returns the first child of the given node.

read only

4.6 or later

lastChild

Node

Returns the last child of the given node.

read only

4.6 or later

localName

String

Returns the local part of the qualified name for the given node.

read only

4.6 or later

namespaceURI

String

Returns the namespace URI for the given node, or null if it is not specified.

read only

4.6 or later

nextSibling

Node

Returns the node immediately following the given node.

read only

4.6 or later

nodeName

String

Returns the name of the given node.

read only

4.6 or later

nodeType

unsigned short

Returns a code representing the type of the given node.

read only

4.6 or later

nodeValue

String

Specifies the value of the given node.

When setting a value for this property, the following error may be thrown:

  • NO_MODIFICATION_ERR: Thrown if the Node object is read only.

When retrieving the value of this property, the following error may be thrown:

  • DOMSTRING_SIZE_ERR: Thrown if the string contains more characters than fit in a DOMString variable.

writable

4.6 or later

ownerDocument

Document

Returns the Document object associated with the given node.

read only

4.6 or later

parentNode

Node

Returns the parent of the given node.

read only

4.6 or later

prefix

String

Specifies the prefix, extracted from the qualified name of the given node, or null if it is unspecified.

When setting a value for this property, the following errors may be thrown:

  • INVALID_CHARACTER_ERR: Thrown if the specified value contains an illegal character.

  • NO_MODIFICATION_ERR: Thrown if the Node object is read only.

  • NAMESPACE_ERR: Thrown if the specified value is malformed.

writable

4.6 or later

previousSibling

Node

Returns the node immediately preceding the current node.

read only

4.6 or later

Node methods

Method name

Description

Availability

addEventListener()

Adds an EventListener object to a set of event listeners for the given node.

4.6 or later

appendChild()

Adds a node to the end of the array of child nodes for the given node.

4.6 or later

cloneNode()

Returns a duplicate of the given node. The duplicate node has no parent.

4.6 or later

dispatchEvent()

Dispatches an Event object created by Document.createEvent().

4.6 or later

hasAttributes()

Returns whether the given node has any attributes.

4.6 or later

hasChildNodes()

Returns whether the given node has any children.

4.6 or later

insertBefore()

Inserts a new node before the given node.

4.6 or later

isSupported()

Tests whether the given node supports a specific feature.

4.6 or later

normalize()

Merges text nodes adjacent to the given element node to create a normalized DOM.

4.6 or later

removeChild()

Removes the specified child from the given element node and returns it.

4.6 or later

removeEventListener()

Removes an event listener from an EventTarget.

4.6 or later

replaceChild()

Removes the specified child from the given and replaces it with another node, then returns the removed node.

4.6 or later

Method: Node.removeEventListener()

Availability

BlackBerry® Device Software version 4.6 or later

The removeEventListener() method removes an EventListener from an EventTarget.

Syntax

Node.removeEventListener( type, listener, useCapture )

Parameters

Parameter

Type

Description

type

String

The type of event.

listener

EventListener

The EventListener function to be removed.

useCapture

boolean

When true, indicates that the EventListener being removed was registered as a capturing listener.

A listener may be registered twice, once as a capturing listener, and once as a non-capturing listener. Each must be removed separately.

Return values

None.

Exceptions

None.

Method: Node.removeChild()

Availability

BlackBerry® Device Software version 4.6 or later

The removeChild() method removes the specified child from the given node and returns it.

Syntax

Node.removeChild( oldChild )

Parameters

Parameter

Type

Description

oldChild

Node

The child node to remove.

Return values

Returns the removed node.

Exceptions

Exception

Description

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the given node is read only.

NOT_FOUND_ERR

This error is thrown if oldChild is not a child of the given node.

Method: Node.replaceChild()

Availability

BlackBerry® Device Software version 4.6 or later

The replaceChild() method removes the specified child from the current node and replaces it with another node, then returns the replaced node.

Syntax

Node.replaceChild( newChild, oldChild )

Parameters

Parameter

Type

Description

newChild

Node

The node with which to replace the old node with.

If newChild is a DocumentFragment object, then the entire contents of the document fragment are appended to the given node.

If newChild already exists as a child of the current node in the tree, it is removed, and then replaced.

oldChild

Node

The child node to replace.

Return values

Returns the replaced node.

Exceptions

Exception

Description

HIERARCHY_REQUEST_ERR

This error is thrown if either newChild or oldChild is one of the current node’s ancestors, or if the current node does not allow children of the type of newChild node.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the current node is read only.

NOT_FOUND_ERR

This error is thrown if oldChild is not a child of the current node.

WRONG_DOCUMENT_ERR

This error is thrown if newChild was created from a different document than the current node.

Method: Node.normalize()

The normalize() method merges any adjacent text nodes contained by the given node and all of its children to create a normalized DOM.

Syntax

Node.normalize()

Parameters

None.

Return values

None.

Exceptions

None.

Method: Node.addEventListener()

Availability

BlackBerry® Device Software version 4.6 or later

The addEventListener() method adds an EventListener object to a set of event listeners for the given node.

Syntax

Node.addEventListener( type, listener, useCapture )

Parameters

Parameter

Type

Description

type

String

The type of event to add.

listener

EventListener

The event listener function to be invoked.

useCapture

boolean

When true, indicates all events of the specified type to the registered EventListener before being dispatched to any EventTargets beneath the given node in the tree. Bubbling events will not trigger the EventListener.

When false, this method dispatches events of the specified type to the registered EventListener before being dispatched to any EventTargets above the given node in the tree.

Return values

None.

Exceptions

None.

See also

Event, EventListener

Method: Node.appendChild()

Availability

BlackBerry® Device Software version 4.6 or later

The appendChild() method adds a node to the end of an array of children of the given node.

Syntax

Node.appendChild( newChild )

Parameters

Parameter

Type

Description

newChild

Node

The node to add.

If newChild is a DocumentFragment object, then the entire contents of the document fragment are appended to the given node.

If newChild already exists in the tree, it is removed, and then replaced.

Return values

Returns the added node.

Exceptions

Exception

Description

HIERARCHY_REQUEST_ERR

This error is thrown if newChild is one of the given node’s ancestors, or if the given node does not allow children of the type of newChild node.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the given node is read only.

WRONG_DOCUMENT_ERR

This error is thrown if newChild was created from a different document than the given node.

Method: Node.cloneNode()

Availability

BlackBerry® Device Software version 4.6 or later

The cloneNode() method returns a duplicate of the given node. The duplicate node has no parent.

If you clone an Element or an Attr node, you should be aware of the following:

When you clone an Element node, you also duplicate its attributes and their values. However, you do not clone any text the Element node contains (since the text is contained in a child text node) unless you specify the deep parameter.

When you clone an Attr node, this method returns a "specified" attribute (that is, the specified property for that attribute is set to true).

Cloning any other type of node simply returns a copy of the node.

Syntax

Node.cloneNode( deep )

Parameters

Parameter

Type

Description

deep

boolean

When true, this method clones the subtree under the given node.

When false, this method only clones the given node; it does not clone the subtree.

Return values

Returns the duplicate node.

Exceptions

None.

Method: Node.dispatchEvent()

Availability

BlackBerry® Device Software version 4.6 or later

The dispatchEvent() method dispatches an Event object created by Document.createEvent().

Syntax

Node.dispatchEvent( event )

Parameters

Parameter

Type

Description

event

Event

The Event object to be dispatched.

Return values

Returns true if the Event.preventDefault() was not called by any of the event listeners that handled the event. The Event.preventDefault() method prevents the default action for the event from occurring; otherwise, returns false.

Exceptions

Exception

Description

UNSPECIFIED_EVENT_TYPE_ERR

This error is thrown if the event type was not specified by initializing the event before calling dispatchEvent(), or if the event type was null.

Method: Node.hasAttributes()

The hasAttributes() method returns whether the specified node has any attributes. If the node is not an element, this method returns false.

Syntax

Node.hasAttributes()

Parameters

None.

Return values

Returns true if the given node is an element with attributes; otherwise, returns false.

Exceptions

None.

Method: Node.hasChildNodes()

The hasChildNodes() method returns whether the given node has any children.

Syntax

Node.hasChildNodes()

Parameters

None.

Return values

Returns true if the given node has any child nodes; otherwise, returns false.

Exceptions

None.

See also

Node.childNodes

Method: Node.insertBefore()

The insertBefore() method inserts a new child node into the current node before the specified child node. This methods allows you to insert a node at a specific location among a number of child nodes.

Syntax

Node.insertBefore( newChild, refChild )

Parameters

Parameter

Type

Description

newChild

Node

The node to insert.

If newChild is a DocumentFragment object, then the entire contents of the document fragment are inserted, in order, before refChild.

If newChild already exists as a child of the current node in the tree, then it is removed, and the new node inserted.

refChild

Node

The existing child node before which newChild is inserted.

If refChild is not specified or is null, then newChild is inserted at the end of the list of children.

Return values

Returns the inserted node.

Exceptions

Exception

Description

HIERARCHY_REQUEST_ERR

This error is thrown if newChild is an ancestor of refChild, or if refChild does not allow children of the type of newChild node.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the given node is read only.

NOT_FOUND_ERR

This error is thrown if refChild is not a child of the current node.

WRONG_DOCUMENT_ERR

This error is thrown if newChild was created from a different document than the current node.

Method: Node.isSupported()

The isSupported() method tests whether the given node supports a specific feature. This method provides similar functionality as the DOMImplementation.hasFeature() method.

Syntax

Node.isSupported( feature, version )

Parameters

Parameter

Type

Description

feature

String

The name of the feature to test.

version

String

The version of the feature to test.

If version is null, this method returns true if any version of the feature is supported.

Return values

Returns true if the specified version of the specified feature is supported; otherwise, returns false.

Exceptions

None.


Was this information helpful? Send us your comments.