Browser support:
Represents a text as a node.
Syntax:
Methods that return the object:
The base interface, through which you can add new functionalities to the
TextNode object, is the
Text interface.
Possible members:
Properties:
Methods:
addEventListener
Registers an event handler function (event listener) for the specified event on the current object.
appendData
Appends the specified text content to the end of the current TextNode , CommentNode or comment element.
attachEvent
Registers an event handler function (event listener) for the specified event on the current object.
cloneNode
Returns an exact copy of the current node.
compareDocumentPosition
Compares the placement of the specified node with the current node in the DOM hierarchy.
deleteData
Removes the specified part of the text content of the current TextNode , CommentNode or comment element.
detachEvent
Removes the specified event handler from the current element that was registered earlier with the attachEvent method.
dispatchEvent
Dispatches the specified event to the current element.
hasAttributes
Returns whether the current element has any attributes specified or not.
hasChildNodes
Returns whether the current node has any child nodes or not.
insertData
Inserts text content into the current TextNode , CommentNode or comment element at the specified position.
isDefaultNamespace
Returns whether the specified namespace URI is the default namespace in the scope of the current node.
isEqualNode
Returns whether the current node is equal to the specified one.
isSameNode
Returns whether the current node is the same node as the specified one.
isSupported
Returns whether the specified DOM module and version is supported by the current node.
lookupNamespaceURI
Retrieves the namespace URI associated with the specified namespace prefix in the scope of the current node.
lookupPrefix
Retrieves the namespace prefix associated with the specified namespace URI in the scope of the current node.
normalize
Puts the subtree that belongs to the current node into a 'normalized' form.
removeEventListener
Removes the specified event handler from the current element that was registered earlier with the addEventListener method.
removeNode
Removes the current element with or without its children from the document tree.
replaceData
Replaces the specified part of the text content of the current TextNode , CommentNode or comment element with a new text.
replaceNode
Replaces the current element with the specified element.
splitText
Breaks the current TextNode object into two TextNode objects at the specified index.
substringData
Returns the part of the current element's text content from the specified position with the specified length.
swapNode
Interchanges the positions of the current element and the specified element in the document hierarchy.
Example HTML code 1:
This example shows how to get a TextNode object:
< head >
< script type = "text/javascript" >
function GetTextNode () {
var textContainer = document . getElementById ( "textContainer" );
var textNode = textContainer. firstChild ;
alert (textNode. data );
}
</ script >
</ head >
< body >
< div id = "textContainer" > This is a simple text in the container. </ div >
< button onclick = "GetTextNode ()" > Get the contents of the container </ button >
</ body >
Did you find this example helpful?
yes
no
Example HTML code 2:
This example shows how to create and insert a TextNode object:
< head >
< script type = "text/javascript" >
function CreateText () {
var textContainer = document . getElementById ( "textContainer" );
var textNode = document . createTextNode ( "Dynamically generated text" );
textContainer. appendChild (textNode);
}
</ script >
</ head >
< body >
< div id = "textContainer" ></ div >
< button onclick = "CreateText ();" > Create a text node! </ button >
</ body >
Did you find this example helpful?
yes
no
Related pages:
External links:
Share:
Digg
Del.icio.us
Reddit
Facebook
Twitter
Diigo
User Contributed Comments