Chapter 3 DynaScript Predefined Objects


DOMText object

Object

Represents textual content.

Syntax

To use a DOMText's property:

DOMText.propertyName

To use a DOMText's method:

DOMText.MethodName( parameter ) 

Description

DOMText objects inherit all of the properties and methods of the DOMCharacterData object.

If there is no markup inside an element's content, the text is contained in a single DOMText object that is the only child of the element. If there is markup, the content is parsed into a list of elements and text nodes that form the list of children of the element.

When a DOMDocument is created (via the toDOMDocument method), there is only one DOMText object for each block of text. Additional DOMText objects can then be added, resulting in adjacent text nodes without intervening markup. You can use the normalize method on a DOMElement to merge adjacent DOMText objects into a single DOMText object.

See also

"DOMCharacterData object"

splitText method

Syntax

DOMText.splitText( offset )

Description

Breaks this text node into two text nodes at the specified offset, keeping both in the tree as siblings. offset is the point where the text is to be split, starting from 0.

After the split, this DOMText object contains the content up to the offset point. The new DOMText node, added as the next sibling of this node, contains the content at or after the offset point.

Return

The new added DOMText node

Example

This script takes an element that has a single text node as child (holding a street address), and adds text to the end of that node by splitting the text and then normalizing:

streetText = streetElement.firstChild;
streetText.splitText(stText.length );
streetElement.lastChild.data = " -- now moved";
streetElement.normalize();

See also

"normalize method"

 


Copyright © 2001 Sybase, Inc. All rights reserved.