Help Center

Local Navigation

Object: Document

Availability

BlackBerry® Device Software version 4.6 or later

Extends

Node

The Document object represents the entire HTML or XML document. It acts as the root of the tree, and provides the primary access to the data of the document.

Document properties

Property name

Type

Description

Status

Availability

defaultView

AbstractView

Returns the default view of the document.

read only

4.6 or later

doctype

DocumentType

Returns the document type declaration associated with the document.

read only

4.6 or later

documentElement

Element

Returns the root element in a document.

read only

4.6 or later

implementation

DOMImplementation

Returns the DOMImplementation object that handles this document.

read only

4.6 or later

parentWindow

Window

Returns a reference to the parent window. If no parent window exists, this property points to the current active window.

read only

4.6 or later

styleSheets

StyleSheetList

Returns an array of all the style sheets in the document.

read only

4.6 or later

Document methods

Method name

Description

Availability

adoptNode()

Adopts a node and its children from an external document to the current document.

4.7.1 or later

createAttribute()

Creates a new Attr object with the given name.

4.6 or later

createAttributeNS()

Creates a new Attr object with the given qualified name and namespace URI.

4.6 or later

createCDATASection()

Creates a new CDATASection object, which represents a block of uninterpreted content.

4.6 or later

createComment()

Creates a new Comment object with the given text as content.

4.6 or later

createDocumentFragment()

Creates an empty DocumentFragment object.

4.6 or later

createElement()

Creates a new Element object of the specified type.

4.6 or later

createElementNS()

Creates a new Element object of the given qualified name and namespace URI.

4.6 or later

createEntityReference()

Creates a new EntityReference object with the given name.

4.6 or later

createEvent()

Creates a new Event object of the given type.

4.6 or later

createNodeIterator()

Creates a new NodeIterator object, which you can use to iterate through a set of Document nodes rooted at the given node.

4.6 or later

createProcessingInstruction()

Creates a new ProcessingInstruction object with the given name and data.

4.6 or later

createRange()

Creates a new Range object.

4.7.1 or later

createTextNode()

Creates a new Text node containing the given text.

4.6 or later

createTreeWalker()

Creates a TreeWalker object, which you can use to traverse the specified document subtree.

4.6 or later

getElementById()

Returns the element node with the given ID value.

4.6 or later

getElementsByTagName()

Returns a NodeList object that contains an array of a document’s descendent element nodes with the specified tag name.

4.6 or later

getElementsByTagNameNS()

Returns a NodeList object that contains an array of a document’s descendent element nodes with the given local name and namespace URI.

4.6 or later

getOverrideStyle()

Retrieves the override CSSStyleDeclaration object for the given element.

4.6 or later

importNode()

Imports a node from a different document.

4.6 or later

Method: Document.adoptNode()

Availability

BlackBerry® Device Software version 4.7.1 or later

The adoptNode() method moves a node and its child nodes from another document to the current document. Unlike the Document.importNode() method, which imports a copy of the source node, the adoptNode() method removes a node from the one document and adds it to another.

If the adopted node has a parent node, this method first deletes the adopted node from the child list of the parent node, then changes the ownerDocument property of the adopted node to reflect the current document.

The adopted node must be inserted into the desired location within the current document tree by using the Node.appendChild() method or a similar method.

Syntax

Document.adoptNode( sourceNode )

Parameters

Parameter

Type

Description

sourceNode

Node

Specifies the node to move to the current document.

Return values

This method returns the new node, or null if the operation is unsuccessful.

Exceptions

Exception

Description

NO_MODIFICATION_ALLOWED_ERR

Thrown if sourceNode is read-only.

NOT_SUPPORTED_ERR

Thrown if sourceNode is of a type that cannot be adopted, such as a Document or DocumentType node.

Method: Document.createAttribute()

Availability

BlackBerry® Device Software version 4.6 or later

The createAttribute() method creates a new Attr node with the given name. Once created, the attribute instance can be bound to an element using Element.setAttributeNode().

This method only populates the Node.nodeName property for the created attribute and sets the attribute’s value to null.

To create an attribute with a qualified name and namespace URI, use Document.createAttributeNS().

Syntax

Document.createAttribute( name )

Parameters

Parameter

Type

Description

name

String

The name of the attribute to create.

Return values

Returns the new attribute node with the Node.nodeName property set to name and the Node.nodeValue property set to an empty string.

Exceptions

Exception

Description

INVALID_CHARACTER_ERR

This error is thrown if name contains an illegal character.

Method: Document.createAttributeNS()

Availability

BlackBerry® Device Software version 4.6 or later

The createAttributeNS() method creates a new Attr object with the given qualified name and namespace URI. Once created, the attribute instance can be bound to an element using Element.setAttributeNode().

Syntax

Document.createAttributeNS( namespaceURI, qualifiedName )

Parameters

Parameter

Type

Description

namespaceURI

String

The namespace of the new attribute.

qualifiedName

String

The qualified name of the attribute to create.

Return values

Returns the new Attr object with the following properties set:

Property

Description

Node.nodeName

The qualified name.

Node.namespaceURI

The namespace URI for the attribute.

Node.prefix

The prefix, extracted from the qualified name of the new attribute. If there is no prefix, this property is set to null.

Node.localName

The local name for the attribute, extracted from the qualified name.

Node.nodeValue

An empty string.

Attr.name

Equivalent to Node.nodeName.

Exceptions

Exception

Description

INVALID_CHARACTER_ERR

This error is thrown if qualifiedName contains an illegal character.

NAMESPACE_ERR

This error is thrown if:
  • qualifiedName is malformed
  • qualifiedName has a prefix, but namespaceURI is null
  • prefix is “xml”, but namespaceURI is not “http://www.w3.org/XML/1998/namespace”
  • qualifiedName is “xmlns”, but namespaceURI is not “http://www.w3.org/2000/xmlns/”

NOT_SUPPORTED_ERR

This error is thrown if the document does not support XML namespaces.

Method: Document.createCDATASection()

Availability

BlackBerry® Device Software version 4.6 or later

The createCDATASection() method creates a new CDATASection object, which represents a block of uninterpreted content.

HTML documents do not support CDATASection objects.

Syntax

Document.createCDATASection( data )

Parameters

Parameter

Type

Description

data

String

The contents of the CDATASection node.

Return values

Returns the new CDATASection object.

Exceptions

None.

See also

CDATASection

Method: Document.createComment()

Availability

BlackBerry® Device Software version 4.6 or later

The createComment() method creates a new Comment object with the given text as content.

Syntax

Document.createComment( data )

Parameters

Parameter

Type

Description

data

String

The contents of the Comment node.

Return values

Returns the new Comment object.

Exceptions

None.

See also

Comment

Method: Document.createDocumentFragment()

Availability

BlackBerry® Device Software version 4.6 or later

The createDocumentFragment() method creates an empty DocumentFragment object.

A DocumentFragment object can be used to hold and move a portion of a document—such as multiple parent nodes and their children—at once.

Syntax

Document.createDocumentFragment()

Parameters

None.

Return values

Returns the new DocumentFragment object.

Exceptions

None.

Method: Document.createElement()

Availability

BlackBerry® Device Software version 4.6 or later

The createElement() method creates a new Element object of the specified type. Attributes can be set directly on the returned object.

If the Element type returned has any attributes with default values, those attributes will be created and attached to the element with their default values.

Syntax

Document.createElement( tagName )

Parameters

Parameter

Type

Description

tagName

String

The type of element to create.

In an XML document, tagName is case-sensitive.

Return values

Returns the new Element object, with the Node.nodeName property set to tagName, and zero or more Attr objects attached, representing the known attributes that have default values.

Exceptions

Exception

Description

INVALID_CHARACTER_ERR

This error is thrown if tagName contains an illegal character.

See also

Attr, Element

Method: Document.createElementNS()

Availability

BlackBerry® Device Software version 4.6 or later

The createElementNS() method creates a new Element object of the given qualified name and namespace URI. Attributes can be set directly on the returned object.

Syntax

Document.createElementNS( namespaceURI, qualifiedName )

Parameters

Parameter

Type

Description

namespaceURI

String

The namespace of the new attribute.

qualifiedName

String

The qualified name of the attribute to create.

Return values

Returns the new Element object with the following properties set:

Property

Description

Node.nodeName

The qualified name.

Node.namespaceURI

The namespace URI for the attribute.

Node.prefix

The prefix, extracted from the qualified name of the new attribute. If there is no prefix, this property is set to null.

Node.nodeValue

An empty string.

Element.tagName

Equivalent to Node.nodeName.

Exceptions

Exception

Description

INVALID_CHARACTER_ERR

This error is thrown if qualifiedName contains an illegal character.

NAMESPACE_ERR

This error is thrown if:

  • qualifiedName is malformed

  • qualifiedName has a prefix, but namespaceURI is null

  • prefix is “xml”, but namespaceURI is not “http://www.w3.org/XML/1998/namespace”

  • qualifiedName is “xmlns”, but namespaceURI is not “http://www.w3.org/2000/xmlns/”

See also

Element

Method: Document.createEntityReference()

Availability

BlackBerry® Device Software version 4.6 or later

The createEntityReference() method creates a new EntityReference object with the given name.

If the referenced entity is known, then that object’s list of child nodes is made the same as the corresponding Entity node.

Syntax

Document.createEntityReference( name )

Parameters

Parameter

Type

Description

name

String

The name of the entity to reference.

Return values

Returns the new EntityReference object.

Exceptions

Exception

Description

INVALID_CHARACTER_ERR

This error is thrown if name contains an illegal character.

NOT_SUPPORTED_ERR

This error is thrown if the document is an HTML document.

Method: Document.createEvent()

Availability

BlackBerry® Device Software version 4.6 or later

The createEvent() method creates a new Event object of the given type.

If the event is to be dispatched via Node.dispatchEvent(), then the appropriate initialization method must be called after the event has been created, and before it is dispatched, in order to initialize the event’s values.

This method is used to create events when it is inconvenient or unnecessary for the user to create an event themselves.

Syntax

Document.createEvent( eventType )

Parameters

Parameter

Type

Description

eventType

String

The type of event to create.

Return values

Returns the new Event object.

Exceptions

Exception

Description

NOT_SUPPORTED_ERR

This error is thrown if the implementation does not support the specified Event interface.

See also

Event

Method: Document.createNodeIterator()

Availability

BlackBerry® Device Software version 4.6 or later

The createNodeIterator() method creates a new NodeIterator object, which you can use to iterate through a set of Document nodes rooted at the given node.

Syntax

Document.createNodeIterator( root, whatToShow, filter, entityReferenceExpansion )

Parameters

Parameter

Type

Description

root

Node

The node to be iterated with its children. The NodeIterator object is initially positioned just before this node. The value of root must not be null.

whatToShow

unsigned long

The types of nodes to show in the tree view presented by the NodeIterator. The value may be one or more of:

  • 0xFFFFFFFF = SHOW_ALL
  • 0x00000001 = SHOW_ELEMENT
  • 0x00000002 = SHOW_ATTRIBUTE
  • 0x00000004 = SHOW_TEXT
  • 0x00000008 = SHOW_CDATA_SECTION
  • 0x00000010 = SHOW_ENTITY_REFERENCE
  • 0x00000020 = SHOW_ENTITY
  • 0x00000040 = SHOW_PROCESSING_INSTRUCTION
  • 0x00000080 = SHOW_COMMENT
  • 0x00000100 = SHOW_DOCUMENT
  • 0x00000200 = SHOW_DOCUMENT_TYPE
  • 0x00000400 = SHOW_DOCUMENT_FRAGMENT
  • 0x00000800 = SHOW_NOTATION

Multiple values may be specified using a bitwise OR.

Note that because attributes, entities, and notations are not the child of any other node, they never appear in the NodeIterator object’s logical view unless root is defined as a Node of that type. If the respective object is not defined as the root, then SHOW_ATTRIBUTE, SHOW_ENTITY, and SHOW_NOTATION have no meaning.

filter

NodeFilter

The filter to use with this NodeIterator object. This parameter may be null.

entityReferenceExpansion

boolean

When true, this method specifies that entity reference nodes should be expanded.

Return values

Returns the new NodeIterator object.

Exceptions

Exception

Description

NOT_SUPPORTED_ERR

This error is thrown if the specified root is null.

See also

NodeIterator

Method: Document.createProcessingInstruction()

Availability

BlackBerry® Device Software version 4.6 or later

The createProcessingInstruction() method creates a new ProcessingInstruction object with the given name and data.

Syntax

Document.createProcessingInstruction( target, data )

Parameters

Parameter

Type

Description

target

String

The target of the processing instruction.

data

String

The data to store in the processing instruction.

Return values

Returns the new ProcessingInstruction object.

Exceptions

Exception

Description

INVALID_CHARACTER_ERR

This error is thrown if target contains an illegal character.

NOT_SUPPORTED_ERR

This error is thrown if the document is an HTML document.

Method: Document.createRange()

Availability

BlackBerry® Device Software version 4.7.1 or later

The createRange() method creates a new empty Range object.

The Range object can be used only to select content that is associated with the current document, or with DocumentFragment or Attr objects for which this document is the owner.

Syntax

Document.createRange()

Parameters

None.

Return values

This method returns the new empty Range object. The boundary points of the Range object that is returned from this method are positioned at the beginning of the corresponding document, before any content.

Exceptions

None.

See also

Range

Method: Document.createTextNode()

Availability

BlackBerry® Device Software version 4.6 or later

The createTextNode() method creates a new Text node containing the given text.

You can create new text nodes to add text to an existing node, then use Node.normalize() to merge them into a single node later on.

Syntax

Document.createTextNode( text )

Parameters

Parameter

Type

Description

text

String

The string of text that the Text node is to contain.

Return values

Returns the new Text object.

Exceptions

None.

See also

Text

Method: Document.createTreeWalker()

Availability

BlackBerry® Device Software version 4.6 or later

The createTreeWalker() method creates a TreeWalker object, which you can use to traverse the specified document subtree.

Syntax

Document.createTreeWalker( root, whatToShow, filter, expandEntityReference )

Parameters

Parameter

Type

Description

root

Node

The node that will serve as the root for this TreeWalker object. The TreeWalker.currentNode property is set to the value of root.

whatToShow

unsigned long

The types of nodes to show in the tree view. The value may be one or more of:

  • 0xFFFFFFFF = SHOW_ALL
  • 0x00000001 = SHOW_ELEMENT
  • 0x00000002 = SHOW_ATTRIBUTE
  • 0x00000004 = SHOW_TEXT
  • 0x00000008 = SHOW_CDATA_SECTION
  • 0x00000010 = SHOW_ENTITY_REFERENCE
  • 0x00000020 = SHOW_ENTITY
  • 0x00000040 = SHOW_PROCESSING_INSTRUCTION
  • 0x00000080 = SHOW_COMMENT
  • 0x00000100 = SHOW_DOCUMENT
  • 0x00000200 = SHOW_DOCUMENT_TYPE
  • 0x00000400 = SHOW_DOCUMENT_FRAGMENT
  • 0x00000800 = SHOW_NOTATION

Multiple values may be specified using a bitwise OR.

Note that because attributes, entities, and notations are not the child of any other node, they never appear in the TreeWalker object’s logical view unless root is defined as a Node of that type. If the respective object is not defined as the root, then SHOW_ATTRIBUTE, SHOW_ENTITY, and SHOW_NOTATION have no meaning.

filter

NodeFilter

The filter to use with this TreeWalker object. This parameter may be null.

entityReferenceExpansion

boolean

When true, this method specifies that entity reference nodes should be expanded.

Return values

Returns the new TreeWalker object.

Exceptions

Exception

Description

NOT_SUPPORTED_ERR

This error is thrown if the specified root is null.

See also

TreeWalker

Method: Document.getElementById()

Availability

BlackBerry® Device Software version 4.6 or later

The getElementById() method returns the Element node with the given ID value.

Syntax

Document.getElementById( elementID )

Parameters

Parameter

Type

Description

elementID

String

The ID of the element to retrieve.

Return values

Returns the Element object with the given ID value, or null if no element with that ID value exists.

Exceptions

None.

Code sample

The following example appends a text node as a child of a new Paragraph element, then appends the Paragraph node as a child of the node divb.

Function appendTextNode() {
	var divb = document.getElementById(‘b’);
var str = document.getElementById(‘a’).value;
var pnode = document.createElement(‘p’);
var tnode = document.createTextNode(str);
	pnode.appendChild(tnode);
divb.appendChild(pnode);

See also

Element

Method: Document.getElementsByTagName()

Availability

BlackBerry® Device Software version 4.6 or later

The getElementsByTagName() method returns a NodeList object that contains an array of a document’s descendent Element nodes with the specified tag name.

Syntax

Document.getElementsByTagName( tagName )

Parameters

Parameter

Type

Description

tagName

String

The name of the tag to match on. Specify a value of “*” to match all elements.

Return values

Returns a new NodeList object containing an array of all the elements with a given tag, in the order in which they are encountered in a preorder traversal of the Document tree.

Exceptions

None.

Method: Document.getElementsByTagNameNS()

Availability

BlackBerry® Device Software version 4.6 or later

The getElementsByTagNameNS() method returns a NodeList object that contains an array of a document’s descendent Element nodes with the given local name and namespace URI.

Syntax

Document.getElementsByTagNameNS( namespaceURI, localName )

Parameters

Parameter

Type

Description

namespaceURI

String

The namespace of the elements to match on. Specify a value of “*” to match all elements.

localName

String

The local name of the elements to match on (that is, the qualified name minus the prefix). Specify a value of “*” to match all local elements.

Return values

Returns a new NodeList object containing an array of all the elements with a given local name and namespace URI, in the order in which they are encountered in a preorder traversal of the Document tree.

Exceptions

None.

Method: Document.getOverrideStyle()

Availability

BlackBerry® Device Software version 4.6 or later

The getOverrideStyle() method retrieves the override CSSStyleDeclaration object for the given element.

Override styles take precedence over authored styles, although authored styles which contain the “!important” declaration maintain precedence and cannot be overridden using this method.

Using this method, you can override an explicitly linked style sheet without changing the authored style sheet itself.

Syntax

Document.getOverrideStyle( elt, pseudoElt )

Parameters

Parameter

Type

Description

elt

Element

The element for which to modify the style.

pseudoElt

String

The pseudo-element for which to modify the style. This parameter may be null.

Return values

Returns the CSSStyleDeclaration object.

Exceptions

None.

Method: Document.importNode()

Availability

BlackBerry® Device Software version 4.6 or later

The importNode() method imports a node from a different document. This method is similar to Node.cloneNode(), except that it functions across documents.

The returned node has no parent, and the source node is not altered or removed from the original document; this method creates a new copy of the source node.

Importing a node creates a new Node object owned by the document the node is imported into, with values identical to the Node.nodeName and Node.nodeType, plus the attributes related to namespaces. Additional information is copied as appropriate to the node type.

Syntax

Document.importNode( importedNode, deep )

Parameters

Parameter

Type

Description

importedNode

Node

The node to import into the current document.

deep

boolean

When true, this method imports the given node and the subtree.

When false, this method only imports the given node; it does not include the subtree.

This parameter has no effect when the given node is an Attr, EntityReference, or Notation node.

Return values

Returns the imported Node.

Exceptions

Exception

Description

NOT_SUPPORTED_ERR

This error is thrown if the node type being imported is not supported.


Was this information helpful? Send us your comments.