how expand/move range object

T

Thomas

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
 
M

Martin Honnen

Thomas said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top