470,591 Members | 2,302 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

how expand/move range object

Hi dudes,

I have a range object for text (not the one in the IE, the one for
Mozilla). Now I have a function to reduce/move the range in the text
to the LEFT, e.g.:
range.setStart(range.startContainer, startPos-1);
range.setEnd(range.endContainer, endPos-1);
range ist the range object created via
window.getSelection.getRangeAt(0).
Now I have the problem to extend or simply move the range to the
RIGHT.
range.setEnd(range.endContainer, endPos + 1);
range.setStart(range.startContainer, startPos + 1);
I thought I could simply switch the sign, but this doesn't work, I get
the following error (yes, I exchanged the order for expanding, so that
first the endContainer is moved and afterwards the startContainer ;-)
):

Error: [Exception... "Index or size is negative or greater than the
allowed amount" code: "1" nsresult: "0x80530001
(NS_ERROR_DOM_INDEX_SIZE_ERR)" location: "xxx.html Line: 79"]
Source File: xxx.html
Line: 79

Thx for any help,
Thomas
Jul 20 '05 #1
1 4610


Thomas wrote:
I have a range object for text (not the one in the IE, the one for
Mozilla). Now I have a function to reduce/move the range in the text
to the LEFT, e.g.:
range.setStart(range.startContainer, startPos-1);
range.setEnd(range.endContainer, endPos-1);
range ist the range object created via
window.getSelection.getRangeAt(0).
Now I have the problem to extend or simply move the range to the
RIGHT.
range.setEnd(range.endContainer, endPos + 1);
range.setStart(range.startContainer, startPos + 1);
I thought I could simply switch the sign, but this doesn't work, I get
the following error (yes, I exchanged the order for expanding, so that
first the endContainer is moved and afterwards the startContainer ;-)
):

Error: [Exception... "Index or size is negative or greater than the
allowed amount" code: "1" nsresult: "0x80530001
(NS_ERROR_DOM_INDEX_SIZE_ERR)" location: "xxx.html Line: 79"]
Source File: xxx.html
Line: 79


That will probably depend on what kind of node the current end or
startContainer is and whether there is anything left to move to. If
needed you must change the container.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by James Hurrell | last post: by
8 posts views Thread by sathyashrayan | last post: by
4 posts views Thread by Karim El Jed | last post: by
7 posts views Thread by Dennis Jones | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.