how expand/move range object

Discussion in 'Javascript' started by Thomas, Jan 23, 2004.

  1. Thomas

    Thomas Guest

    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
     
    Thomas, Jan 23, 2004
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Jan 23, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    46
    Views:
    971
    Antoon Pardon
    Jul 25, 2006
  2. Lambda
    Replies:
    2
    Views:
    401
    James Kanze
    Jul 16, 2008
  3. Eduardo78
    Replies:
    0
    Views:
    256
    Eduardo78
    Nov 3, 2005
  4. Andrew Tomazos
    Replies:
    2
    Views:
    625
    Nobody
    Dec 12, 2011
  5. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    155
    Tomoyuki Kosimizu
    Nov 27, 2003
Loading...

Share This Page