Visit Mozilla.org

DOM:range.setEnd

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Sets the end position of a Range.

[edit] Syntax

range.setEnd(endNode, endOffset);
endNode 
The Node to end the Range
endOffset 
An integer greater than or equal to zero representing the offset for the end of the Range from the start of endNode.

[edit] Example

range = document.createRange();
endNode = document.getElementsByTagName("p").item(3);
endOffset = document.getElementsByTagName("p").item(3).childNodes.length;
range.setEnd(endNode,endOffset);

[edit] Notes

If the endNode is a Node of type Text, Comment, or CDATASection, then endOffset is the number of characters from the start of endNode. For other Node types, endOffset is the number of child nodes between the start of the endNode.

Setting the end point above (higher in the document) the start point will throw an NS_ERROR_ILLEGAL_VALUE exception.

[edit] Specification

DOM Level 2 Range: Range.setEnd