Text
Summary
Represents a section of text content (character data) within the document. It is not an element and cannot contain any child elements.
Inherits from CharacterDataCharacterData
Properties
- wholeText
- Retrieves the immediate text child nodes of the parent node, that are adjacent to the text node.
Methods
- replaceWholeText
- Replaces the text of the current object.
- splitText
- Divides a text node at the specified index.
Events
No events.
Inherited from CharacterData
Properties
- html/elements/data
- Sets or gets a node’s character data.
- length
- Gets the number of characters in a text node.
Methods
- appendData
- Appends a string to the end of the character data.
- deleteData
- Removes a specified range of characters from the node.
- insertData
- Inserts a new character string into the node at the specified offset.
- replaceData
- Replaces a specified range of characters in the node with a new character string.
- substringData
- Extracts a range of characters from the node.
Events
No events.
Inherited from Node
Properties
- attributes
- Associatve array containing the attributes of node.
- childNodes
- Gets a collection of direct Node descendants of the Node, including Element, Text and any other type of nodes.
- firstChild
- Gets a reference to the first child node in the childNodes collection of the object. If the node is childless, null is returned.
- lastChild
- Gets a reference to the last child in the childNodes collection of an object.
- localName
- Retrieves the local name of the fully qualified XML declaration for a node.
- namespaceURI
- Retrieves the namespace URI of the fully qualified XML declaration for a node.
- nextSibling
- Retrieves the next child node of the parent of the node.
- nodeName
- Gets the name of a particular type of node.
- nodeType
- Retrieves the type of the requested node.
- nodeValue
- Gets or sets the value of a Node, if the type of Node supports it.
- ownerDocument
- Retrieves the document object associated with the node.
- parentNode
- Retrieves the parent node in the document hierarchy.
- prefix
- Sets or retrieves the prefix of the fully qualified XML declaration for a node.
- previousSibling
- Retrieves the previous child node of the parent of the node.
- textContent
- Sets or retrieves the text content of a node and any child nodes.
Methods
- appendChild
- Appends an element as a child to the object.
- cloneNode
- Copies a reference to the object from the document hierarchy.
- compareDocumentPosition
- Compares the position of two nodes in a document.
- empty
- Cancels the current selection, sets the selection type to none, and sets the item property to null.
- hasAttributes
- Returns whether this node (if it is an element) has any attributes
- hasChildNodes
- Gets a value that indicates whether the Node has any direct Node descendant of any type.
- insertBefore
- Inserts a child into the node, immediately before the specified reference child node.
- isDefaultNamespace
- Indicates whether or not a namespace is the default namespace for a document.
- isEqualNode
- Determines whether two nodes are equal in their type, name and namespace.
- isSameNode
- Determines if two nodes are the same node.
- isSupported
- Returns a value indicating whether or not the object supports a specific DOM standard.
- lookupNamespaceURI
- Gets the URI of the namespace associated with a namespace prefix, if any.
- lookupPrefix
- Gets the namespace prefix associated with a URI, if any.
- normalize
- Merges adjacent DOM objects to produce a normalized document object model.
- removeChild
- Removes a child node from a node.
- replaceChild
- Replaces an existing child node with a new child node.
Events
No events.
Inherited from EventTarget
Properties
No properties.
Methods
- addEventListener
- Registers an event handler for the specified event type.
- dispatchEvent
- Sends an event to the current element.
- removeEventListener
- Removes an event handler that the addEventListener method registered.
Events
No events.
Examples
This example uses the TextNode object to change the text of an li object.
<script>
function fnChangeText(){
var oTextNode = document.createTextNode("New List Item 1");
var oReplaceNode = oItem1.firstChild.replaceNode(oTextNode);
}
</script>
<ul onclick = "fnChangeText()">
<li id = "oItem1">List Item 1</li>
</ul>
Notes
Use the createTextNode method to create a TextNode object. After you create the TextNode, you can add to it using the appendChild or insertBefore methods.
Attributions
Microsoft Developer Network: [TextNode Object Article]