Package | dom.core |
Class | public class Text |
Inheritance | Text CharacterData Node Object |
Subclasses | CDATASection |
Introduced in: | DOM 1 Core |
Modified in: | DOM 3 Core |
New documents have a single Text node for each block of text. Over time, more Text nodes may be created as the document's content changes. The Node.normalize() method merges adjacent Text objects back into a single node for each block of text.
See also
Property | Defined By | ||
---|---|---|---|
DOM 1 Core attributes : NamedNodeMap [read-only]
Returns an unordered collection of Attr nodes. | Node | ||
Non-Standard baseName : DOMString [read-only]
Returns the base name for the name qualified with the namespace. | Node | ||
DOM 3 Core baseURI : DOMString [read-only]
The absolute base URI of this node or null if the implementation
wasn't able to obtain an absolute URI. | Node | ||
DOM 1 Core childNodes : NodeList [read-only]
Returns an ordered collection of node objects that are children of
the current element. | Node | ||
DOM 1 Core data : DOMString
The character data of the node that implements this interface. | CharacterData | ||
Non-Standard dataType : *
Specifies the data type for this node. | Node | ||
Non-Standard definition : Node [read-only]
Returns the definition of the node in the document type definition (DTD) or schema. | Node | ||
DOM 1 Core firstChild : Node [read-only]
Returns the node's first child in the tree, or null if the node is
childless. | Node | ||
DOM 3 Core isElementContentWhitespace : Boolean [read-only]
Returns a Boolean value indicating whether or not the text node contains whitespace within its content. | Text | ||
DOM 1 Core lastChild : Node [read-only]
Returns the last child of a node. | Node | ||
DOM 1 Core length : Number [read-only]
The number of 16-bit units that are available through data and the
substringData method below. | CharacterData | ||
DOM 2 Core localName : DOMString [read-only]
Returns the local part of the qualified name of this node. | Node | ||
DOM 2 Core namespaceURI : DOMString [read-only]
The namespace URI of the node, or null if it is unspecified (read-only). | Node | ||
DOM 1 Core nextSibling : Node [read-only]
Returns the node immediately following the specified one in its
parent's childNodes list, or null if the specified node is the
last node in that list. | Node | ||
DOM 1 Core nodeName : DOMString [read-only]
Returns the name of the current node as a string. | Node | ||
Non-Standard nodePrincipal : nsIPrincipal [read-only]
Returns the nsIPrincipal object representing current security
context of the node. | Node | ||
DOM 1 Core nodeType : Number [read-only]
Returns an integer code representing the type of the node. | Node | ||
Non-Standard nodeTypedValue : *
Contains the node value expressed in its defined data type. | Node | ||
Non-Standard nodeTypeString : DOMString [read-only]
Returns the node type in string form. | Node | ||
DOM 1 Core nodeValue : DOMString
Returns or sets the value of the current node. | Node | ||
DOM 1 Core ownerDocument : Document [read-only]
The Document object associated with this node. | Node | ||
DOM 1 Core parentNode : Node [read-only]
Returns the parent of the specified node in the DOM tree. | Node | ||
Non-Standard parsed : Boolean [read-only]
Indicates the parsed status of the node and child nodes. | Node | ||
DOM 2 Core prefix : DOMString
Returns the namespace prefix of the specified node, or null if no
prefix is specified. | Node | ||
DOM 1 Core previousSibling : Node [read-only]
Returns the node immediately preceding the specified one in its
parent's childNodes list, null if the specified node is the first
in that list. | Node | ||
Non-Standard specified : Boolean [read-only]
Indicates whether the node (usually an attribute) is explicitly specified or derived
from a default value in the document type definition (DTD) or schema. | Node | ||
Non-Standard text : DOMString
Represents the text content of the node or the concatenated text representing the node and its descendants. | Node | ||
DOM 3 Core textContent : DOMString
Gets or sets the text content of a node and its descendants. | Node | ||
DOM 3 Core wholeText : DOMString
Returns all text of all Text nodes logically adjacent to this node, concatenated in document order. | Text | ||
Non-Standard xml : DOMString [read-only]
Contains the XML representation of the node and all its descendants. | Node |
Method | Defined By | ||
---|---|---|---|
Associates a function with a particular event and binds the event to the current node. | Node | ||
DOM 3 Events addEventListenerNS(namespaceURI:DOMString, type:DOMString, listener:EventListener, useCapture:Boolean):void
Registers an event listener, depending on the useCapture parameter, on the
capture phase of the DOM event flow or its target and bubbling phases. | Node | ||
Adds a node to the end of the list of children of a specified parent node. | Node | ||
Append the string to the end of the character data of the node. | CharacterData | ||
Returns a duplicate of the current node. | Node | ||
Compares the position of the current node against another node in any other document. | Node | ||
DOM 1 Core deleteData(offset:Number, count:Number):void
Remove a range of 16-bit units from the node. | CharacterData | ||
Dispatches an event to fire on a node artificially. | Node | ||
This method returns a specialized object which implements the
specialized APIs of the specified feature and version, as specified
in DOM Features. | Node | ||
Retrieves the object associated to a key on a this node. | Node | ||
DOM 2 Core hasAttributes():Boolean
Returns a boolean value of true or false, indicating if the current element
has any attributes or not. | Node | ||
DOM 1 Core hasChildNodes():Boolean
Returns a value that indicates whether the object has children. | Node | ||
Inserts the specified node before a reference element as a child of
the current node. | Node | ||
Insert a string at the specified 16-bit unit offset. | CharacterData | ||
Returns true if the namespace is the default namespace on the given
node or false if not. | Node | ||
Tests whether two nodes are equal. | Node | ||
Returns whether this node is the same node as the given one. | Node | ||
Tests whether the DOM implementation implements a specific feature
and that feature is supported by this node. | Node | ||
Takes a prefix and returns the namespaceURI associated with it on the
given node if found (and null if not). | Node | ||
Returns the prefix for a given namespaceURI if present, and null if not. | Node | ||
DOM 1 Core normalize():void
Puts the specified node and all of its subtree into a "normalized"
form. | Node | ||
Removes a child node from the object. | Node | ||
Removes an event listener. | Node | ||
DOM 3 Events removeEventListenerNS(namespaceURI:DOMString, type:DOMString, listener:EventListener, useCapture:Boolean):void
Removes an event listener. | Node | ||
Replaces an existing child element with a new child element. | Node | ||
Replace the characters starting at the specified 16-bit unit offset
with the specified string. | CharacterData | ||
Replaces the text of the node and all of its logically adjacent text nodes
with the specified text. | Text | ||
Applies the specified pattern-matching operation to this node's context and returns the list of matching nodes as IXMLDOMNodeList. | Node | ||
Applies the specified pattern-matching operation to this node's context and returns the first matching node. | Node | ||
Associate an object to a key on this node. | Node | ||
Breaks the Text node into two nodes at the specified offset, keeping both
nodes in the tree as siblings. | Text | ||
Extracts a range of data from the node. | CharacterData | ||
Processes this node and its children using the supplied Extensible Stylesheet Language Transformations
(XSLT) style sheet and returns the resulting transformation. | Node | ||
Processes this node and its children using the supplied Extensible Stylesheet Language Transformations (XSLT) style sheet
and returns the resulting transformation. | Node |
DOM 3 Core isElementContentWhitespace | property |
isElementContentWhitespace:Boolean
[read-only] Introduced in: | DOM 3 Core |
Returns a Boolean value indicating whether or not the text node contains whitespace within its content. This determination is made during the loading of the document, or if validation occurs when Document.normalizeDocument() is called.
public function get isElementContentWhitespace():Boolean
See also
DOM 3 Core wholeText | property |
wholeText:DOMString
Product Version : | 3.5 |
Introduced in: | DOM 3 Core |
Returns all text of all Text nodes logically adjacent to this node, concatenated in document order.
public function get wholeText():DOMString
public function set wholeText(value:DOMString):void
See also
<p>Thru-hiking is great! <strong>No insipid election coverage!</strong> However, <a href="http://en.wikipedia.org/wiki/Absentee_ballot">casting a ballot</a> is tricky.</p>
You decide you don’t like the middle sentence, so you remove it:
para.removeChild(para.childNodes[1]);
Later, you decide to rephrase things to, “Thru-hiking is great, but casting a ballot is tricky.” while preserving the hyperlink. So you try this:
para.firstChild.data = "Thru-hiking is great, but ";
All set, right? Wrong! What happened was you removed the strong element, but the removed sentence’s element separated two text nodes, one for the first sentence and one for the first word of the last. Instead, you now effectively have this:
<p>Thru-hiking is great, but However, <a href="http://en.wikipedia.org/wiki/Absentee_ballot"> casting a ballot</a> is tricky.</p>
You’d really prefer to treat all those adjacent text nodes as a single one. That’s where wholeText comes in: if you have multiple adjacent text nodes, you can access the contents of all of them using wholeText. Let’s pretend you never made that last mistake. In that case, we have:
assert(para.firstChild.wholeText == "Thru-hiking is great! However, ");
wholeText is just a property of text nodes that returns the string of data making up all the adjacent (i.e. not separated by an element boundary) text nodes together.
Now let’s return to our original problem. What we want is to be able to replace the whole text with new text. That’s where replaceWholeText() comes in:
para.firstChild.replaceWholeText("Thru-hiking is great, but ");
We’re removing every adjacent text node (all the ones that constituted the whole text) but the one on which replaceWholeText() is called, and we’re changing the remaining one to the new text. What we have now is this:
<p>Thru-hiking is great, but <a href="http://en.wikipedia.org/wiki/Absentee_ballot"> casting a ballot</a> is tricky.</p>
Some uses of the whole-text functionality may be better served by using Node.textContent or the longstanding innerHTML; that’s fine and probably clearer in most circumstances. If you have to work with mixed content within an element as here, however, wholeText and replaceWholeText() may be useful.
DOM 3 Core replacewholeText | () | method |
public function replacewholeText(content:DOMString):Text
Product Version : | 3.5 |
Introduced in: | DOM 3 Core |
Replaces the text of the node and all of its logically adjacent text nodes with the specified text. The replaced nodes are removed, including the current node, unless it was the recipient of the replacement text.
Note: This method returns the text node which received the replacement text, or null if the replacement text is an empty string. The returned node is the current node unless the current node is read only, in which case the returned node is a newly created text node of the same type which has been inserted at the location of the replacement.
Note (Mozilla): Firefox's implementation of this method does not yet support EntityReference nodes as defined by the specification.
Parameters
content:DOMString — Specifying the text with which to replace the node's current contents.
|
Text — The Text node created with the specified content.
|
DOMException — NO_MODIFICATION_ALLOWED_ERR : One of the
text nodes being replaced is read only.
|
See also
DOM 1 Core splitText | () | method |
public function splitText(offset:Number):Text
Introduced in: | DOM 1 Core |
Breaks the Text node into two nodes at the specified offset, keeping both nodes in the tree as siblings.
Note: After the split, the current node contains all the content up to the specified offset point, and a newly created node of the same type contains the remaining text. The newly created node is returned to the caller. If the original node had a parent, the new node is inserted as the next sibling of the original node. If the offset is equal to the length of the original node, the newly created node has no data.
Parameters
offset:Number — 16-bit integer offset at which to split; the first character in the node is numbered zero.
|
Text — The new node, of the same type as this node.
|
DOMException — INDEX_SIZE_ERR : The specified offset is negative or is greater than the number of 16-bit units in the node's text.
| |
DOMException — NO_MODIFICATION_ALLOWED_ERR : The node is read only.
|
See also