# CharacterData : Node
Return to: HTML DOM Level 2 index

Object for accessing and processing character data in the DOM.

## Platform Support

IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | ---
no | 1.0+ | no | 7.0+ | 1.0+

## Constructors

Constructor | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
CharacterData Constructor() : CharacterData Object for accessing and processing character data in the DOM. | Show Details | no | 1.0+ | no | 7.0+ | 1.0+

### CharacterData() : CharacterData

Object for accessing and processing character data in the DOM.

Returns

CharacterData |

Visibility
  internal

## Inherited Properties

Property | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
attributes : NamedNodeMap Attributes for an element node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/attributes.html

Remarks

  This property returns a listing of all the attributes bound to this `Node`. Since only `Element` nodes support attributes, most `Node` types will return a null value for this property.

  `NamedNodeMap`s are essentially the DOM-equivilant of a hash. This property provides an alternative to the specific <method>Element.getAttribute</method> and <method>Element.hasAttribute</method> methods, which are usually used when you already know which attributes an element has. For those circumstances when you want to do some automatic discovery of attributes and their values, this property provides a convenient way to iterate through the element's attributes.

  This property also has the added benefit of being usable across all nodes, not just `Element` nodes. Therefore no checking needs to be done ahead of time to verify if a node is an `Element`; rather you can iterate over the <property>attributes</property> list, since any element that has no attributes, or any other DOM node, will have a null value for this property.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

childNodes : NodeList Child nodes of the current node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/children.html

Remarks

  The list of nodes that are immediate children of this node. The DOM is a heirarchial structure of `Node` objects. This property, combined with the <property>parentNode</property> properties provide the basics for defining this structure. Several convenience properties are provided for accessing some frequently-used children nodes, namely the <property>firstChild</property> and <property>lastChild</property> properties.

  Since the `NodeList` class can be referenced as an array as well as its object-oriented interface, one can easily iterate through the contents of a node using standard JavaScript `for` loops. Because this property is read-only, you cannot alter the `NodeList` to effect this node's contents. Instead, the methods for addeding and removing nodes should be used, which will result in this being updated automatically.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

firstChild : Node First child node of the current node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/nodetree.html

Remarks

  Returns the first child node from the list of the current node's children. If this node doesn't have any children, a null value will be returned.

  This is functionally equivilant to invoking `node.<property>childNodes</property>.<method>NodeList.item</method>(0)`, though this method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

lastChild : Node Last child node of the current node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/nodetree.html

Remarks

  Returns the last child node from the list of the current node's children. If this node doesn't have any children, a null value will be returned.

  This is functionally equivilant to invoking `node.<property>childNodes</property>.<method>NodeList.item</method>(node.<property>childNodes</property>.<property>NodeList.length</property> - 1)`, though this method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

localName : String Local part of an element or attribute name if it the node was defined with an XML Namespace. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

namespaceURI : String URI of the namespace for an element or attribute node if the node was defined with an XML Namespace. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

nextSibling : Node Sibling node immediately after the current node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/nodetree.html

Remarks

  Returns the next node to the current one within the parent node's children. If this node is the last child within it's parent, then a null value will be returned.

  When working with a node, it is often useful to be able to manipulate or search the nodes surrounding it. For instance, if given a node representing a label, you might want to find the text node immediately next to it. To help with this, the <property>nextSibling</property> property allows you to traverse to neighboring nodes in the DOM.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

nodeName : String Name of the node. Same as tag name for element nodes. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/aboutnodes.html

Remarks

  This returns a name that represents this node's name. Depending on the type of object this is, this property will either return the name identifying this object; for instance, if this node is a `Element` or `Attr` object, then the tag or attribute name is returned. In other cases some place-holder text will be returned.

  <property>nodeName</property> node-type values<columns><column><name>Type</name><align>left</align></column><column><name>Value</name><align>left</align></column></columns><rows><row><column>`Attr`</column><column> Attribute name </column></row><row><column>`CDATASection`</column><column>`#cdata-section`</column></row><row><column>`Comment`</column><column>`#comment`</column></row><row><column>`Document`</column><column>`#document`</column></row><row><column>`DocumentFragment`</column><column>`#document-fragment`</column></row><row><column>`DocumentType`</column><column> Document type name </column></row><row><column>`Element`</column><column> Tag name </column></row><row><column>`Entity`</column><column> Entity name </column></row><row><column>`EntityReference`</column><column> Name of entity referenced </column></row><row><column>`Notation`</column><column> Notation name </column></row><row><column>`ProcessingInstruction`</column><column> Target </column></row><row><column>`Text`</column><column>`#text`</column></row></rows>

  If <glossary>XML Namespaces</glossary> were defined for this node and this node is a `Element` or `Attr` object (since these are the only node types that support the use of <glossary>namespaces</glossary>), this property returns the node name including the <property>prefix</property> and <property>localName</property>.

  Returns an upper case tag name.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

nodeType : Number Type of node. See Remarks for valid values. | Show Details | 5.5+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

- IE: IE 5.0 on Windows does not assign nodeType attributes. Fixed in IE 5.5.

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/aboutnodes.html

Remarks

  This property returns an integer indicating what type of DOM `Node` this object represents.

  Because the `Node` class is inherited by several other, more specific DOM objects, this property is a programmatic way of determining what an arbitrary node is, and therefore can tell the programmer how to interact with it. There are a series of constants defined in this object that can be used to refer to this property:

  <property>nodeList</property> constant values<columns><column><name>Value</name><align>right</align></column><column><name>Constant</name><align>left</align></column></columns><rows><row><column>`1`</column><column><property>ELEMENT_NODE</property></column></row><row><column>`2`</column><column><property>ATTRIBUTE_NODE</property></column></row><row><column>`3`</column><column><property>TEXT_NODE</property></column></row><row><column>`4`</column><column><property>CDATA_SECTION_NODE</property></column></row><row><column>`5`</column><column><property>ENTITY_REFERENCE_NODE</property></column></row><row><column>`6`</column><column><property>ENTITY_NODE</property></column></row><row><column>`7`</column><column><property>PROCESSING_INSTRUCTION_NODE</property></column></row><row><column>`8`</column><column><property>COMMENT_NODE</property></column></row><row><column>`9`</column><column><property>DOCUMENT_NODE</property></column></row><row><column>`10`</column><column><property>DOCUMENT_TYPE_NODE</property></column></row><row><column>`11`</column><column><property>DOCUMENT_FRAGMENT_NODE</property></column></row><row><column>`12`</column><column><property>NOTATION_NODE</property></column></row></rows>

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

nodeValue : String Value of the current node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/aboutnodes.html

Remarks

  This represents the value of the node. Only `Attr`, `CDATASection`, `Comment`, `ProcessingInstruction`, and `Text` objects can contain a value in this property. For all other types of objects this property will return null, and setting it to a different value has no effect.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

ownerDocument : Document Document object that contains this node. | Show Details | 6.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/document.html

Remarks

  Refers to the `Document` object that this node exists in. Because a node must be created as a child of a `Document`, and since `Node` objects cannot be moved arbitrarily from one document to another (not without duplicating it), this is a way of referring to the parent document for a node so that document-wide method calls can be used for a node.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

parentNode : Node Parent node of the current node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/nodetree.html

Remarks

  This property contains a reference to the parent node for the current node. Since the DOM is a heirarchial structure of nodes, the <property>parentNode</property> and <property>childNodes</property> properties tie the collection of nodes together.

  Not all nodes can have parents however. `Attr`, `Document`, `DocumentFragment`, `Entity` and `Notation` objects and as such will contain a null value for this property. As well this property will be null for newly-created nodes that have yet to be added to a location within the DOM tree.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

prefix : String Namespace prefix for an element or attribute node if the node was defined with an XML Namespace. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

Availability

  HTML DOM Level 2|W3C

previousSibling : Node Sibling node immediately before the current node. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/nodetree.html

Remarks
  Returns the previous node to the current one within the parent node's children. If this node is the first child within it's parent, then a null value will be returned.
Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

## Properties

Property | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
data : String Character data of the current node. | Show Details | no | 1.0+ | no | 7.0+ | 1.0+

Remarks
  The `data` property does not have a size limitation, but `data` is subject to the limitations of the size of a `String` object. If the content `data` is too large, use `substringData` to retrieve the character data in chunks.
Availability

  HTML DOM Level 2|W3C

length : Number Length of the content of the data property or substringData method. | Show Details | no | 1.0+ | no | 7.0+ | 1.0+

Remarks
  Length of the content available from the `data` property or the `substringData` method. If the content of `data` is empty, the value of `length` will be zero.
Availability

  HTML DOM Level 2|W3C

## Inherited Functions

Method | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
hasAttributes() : Boolean Returns true if the node is an element node with attributes. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.3+

Returns

Boolean |

  ### Using hasAttributes

      var obj = document.Document.getElementById('EmailAddress');
                              if (obj.hasAttributes()) {
                              window.alert("The node " + obj.Node.nodeName + " has attributes");
                              }

  For more examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/attributes3.html

Remarks
  Returns true if this node is an `Element` and has any attributes. Returns false if there are none. Equivilant to checking `node.`attributes`.<property>NamedNodeMap.length</property> > 0`.
See Also

  Element.getAttribute|Element.hasAttribute|Node.attributes

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

hasChildNodes() : Boolean Returns true if the node has child nodes. | Show Details | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+

Returns

Boolean |

  ### Using hasChildNodes

      var obj = document.Document.getElementById('EmailAddress');
                              if (obj.hasChildNodes()) {
                              window.alert("The node " + obj.Node.nodeName + " has children");
                              }

Remarks
  Returns true if this node has any child nodes. Returns false if there are none. Equivilant to checking `node.`childNodes`.`NodeList.length` > 0`.
See Also

  Node.childNodes

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

isSupported(String feature, [String version]) : Boolean Returns true if the specified feature and version are supported. | Show Details | no | 1.0+ | 6.0+ | 7.0+ | 1.0+

Parameters

String | feature | Name of the feature.
String | version | (optional)Version of the feature.

Returns

Boolean |

Remarks
  Tests whether a node supports the specified feature. Similar to the `DOMImplementation.hasFeature` method and takes the same feature names. If version is null, returns true if any version of the feature is supported.
See Also

  DOMImplementation.hasFeature

Availability

  HTML DOM Level 2|W3C

normalize() : void Merges text nodes adjacent to the element to create a normalized DOM. | Show Details | N/A | 1.0+ | 6.0+ | 7.0+ | 1.0+

- IE: May crash IE 6.0.

Returns

void |

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/splittext.html

Remarks
  Normalizes any `Text` nodes contained under this node and all of its children. Merges any adjacent `Text` nodes into one object, so that the nodes reflect how they would be structured if this XML document were freshly loaded.

  `Normalize()` is useful for manipulating the text content of nodes for editing. Instead of worrying about altering existing `Text` nodes, you can simply add new nodes and perform the `normalize` when you finish your updates.

Availability

  HTML DOM Level 1|HTML DOM Level 2|W3C

## Functions

Method | Action | IE | Mozilla | Netscape | Opera | Safari
--- | --- | --- | --- | --- | --- | ---
appendData(String arg) : void Appends the specified string to the node text. | Show Details | 6.0+ | 1.0+ | no | 7.0+ | 1.0+

Parameters

String | arg | String to append.

Returns

void |

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/data.html

Remarks
  Appends the specified string to the end of the current character data content, which will then be available through the `data` property.
Throws
    Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
See Also

  CharacterData.deleteData|CharacterData.insertData|CharacterData.replaceData

Availability

  HTML DOM Level 2|W3C

deleteData(Number offset, Number count) : void Deletes the indicated range of text. | Show Details | 6.0+ | 1.0+ | no | 7.0+ | 1.0+

Parameters

Number | offset | Character offset inside the content from which to start deleting.
Number | count | Number of characters to delete. If the range of characters is greater than the length of the content of the node, then all characters from offset to the end of the string are deleted.

Returns

void |

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/data.html

Remarks
  Removes the specified range of characters from content of the node and shifts any remaining text downward. if the characters are successfully deleted, updates the properties of the node to indicate the new content and size.
Throws
    Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
    Raises an INDEX_SIZE_ERR error if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
See Also

  CharacterData.appendData|CharacterData.insertData|CharacterData.replaceData

Availability

  HTML DOM Level 2|W3C

insertData(Number offset, String arg) : void Inserts the supplied text at the indicated character offset | Show Details | 6.0+ | 1.0+ | no | 7.0+ | 1.0+

Parameters

Number | offset | Character offset inside the content at which to insert the new string.
String | arg | String to insert.

Returns

void |

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/data.html

Remarks
  Performs the opposite of `deleteData`.
Throws
    Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
    Raises an INDEX_SIZE_ERR if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
See Also

  CharacterData.appendData|CharacterData.deleteData|CharacterData.replaceData

Availability

  HTML DOM Level 2|W3C

replaceData(Number offset, Number count, String arg) : void Substitutes the indicated range of text with the supplied string | Show Details | 6.0+ | 1.0+ | no | 8.0+ | 1.0+

Parameters

Number | offset | Character offset inside the content at which to start the replacement.
Number | count | Number of characters to replace. If the range of characters is greater than the length of the content of the node, all characters from offset to the end of the string are replaced.
String | arg | Text string to replace the specified range.

Returns

void |

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/data.html

Remarks
  Replaces a specific range of text within the content of the node with the supplied string. Equivilant to invoking `deleteData`, followed by `insertData` using the same `offset`.
Throws
    Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
    Raises an INDEX_SIZE_ERR error if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
See Also

  CharacterData.appendData|CharacterData.deleteData|CharacterData.insertData

Availability

  HTML DOM Level 2|W3C

static substringData(Number offset, Number count) : String Returns the specified range of text. | Show Details | 6.0+ | 1.0+ | no | 7.0+ | 1.3+

Parameters

Number | offset | The character offset inside the content to return.
Number | count | The number of characters to return.

Returns

String |

  For examples, see the quirksmode test page:

  http://www.quirksmode.org/dom/tests/data.html

Remarks
  Often used for extracting easily-processable regions of text, this method extracts a region of text from the node's content and returns it.
Throws
    Throws a DOMException specifying NO_MODIFICATION_ALLOWED if the node is read-only. Throws an INDEX_SIZE_ERR
    Throws a DOMException specifying INDEX_SIZE_ERR if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
Availability

  HTML DOM Level 2|W3C

## Remarks

`CharacterData` provides a set of attributes and methods for accessing character data in the DOM. This object is always inherited by other objects that require this functionality, such as `Text` and `CDATASection`.

`CDATASection` methods manipulate text ranges and considers that the content of the node may be larger than the limits of the `String` object, so `CDATASection` methods all work with numeric character offsets and text ranges. You should already know the ranges that you will need before invoking these methods.

<note>

The content of this node is represented as `UTF-16`.

</note>

## References

Comment|Text

## Availability

HTML DOM Level 2|W3C

text_javascript aptana_docs