Javascript Reference
Categories: Range

javascript Range endOffset

@March 15, 2008, 1:22 a.m.
endOffsetFirefox/Netscape/NN 6 IE n/a Chrome/Safari/DOM 2  

Read-only  

Returns an integer count of characters or nodes for the end point's location within the node reported by the endContainer property. If the endContainer is a text node, the endOffset property counts the number of characters to the right of the first character of that text node. If the endContainer is an element node, the endOffset property counts the number of nodes between the start of the containing node's content and the end point.

 

As an example, consider the following document segment that shows a text range in boldface characters, with the start and end points signified by pipe characters:

<>One paragraph with |pa<span> nested</spa>| element inside.</p>n
 

Note that the start point is within a text node, while the end point sits just outside the span element end tag. The Range object's properties report values as shown in the following table.

 
PropertyValueDescription
commonAncestorContainer[object HTMLParagraphElement]The p element embraces both the start and end points.
startContainer[object Text]Start point is within a text node.
startOffset19Start point is at the 20th (zero-based index of 19) character from the start of its container, the text node.
endContainer[object HTMLParagraphElement]End point is designated as the end of the span element, which makes the next outer p element the end point's container.
endOffset2End point is at the 3rd (zero-based index of 2) node in the context of its endContainer p element (first node is a text node; second node is the span element; end point is at the start of the third node of the p element).
 
Example
 
var rngEndOff = rng.endOffset;
 
Value

Integer.

 
Default

None.


Powered by Linode.