SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looking for IE equivalent of range.startContainer / range.endContainer

    I'm trying to use JavaScript to wrap selected elements in a new div. Using the following HTML as an example:

    HTML Code:
    <html>
    <body>
    <p id="p1">Paragraph 1</p>
    <p id="p2">Paragraph 2</p>
    <p id="p3">Paragraph 3</p>
    <p id="p4">Paragraph 4</p>
    </body>
    </html>
    With Firefox I can get the selection as a range, which has the properties startContainer and endContainer.

    Say that the selection runs from 'Paragraph 2' to 'Paragraph 4'. The value of startContainer will be the 'Paragraph 2' text node, and I can work back to get the parent paragraph element node (call it 'startNode'). Similarly, I can work back from endContainer to get a paragraph element node (call it 'endNode').

    I can then take startNode, endNode and the elements in between, add them to a new div, and put the new div back.

    The problem is that I can't find an equivalent for IE. I can't find a way of translating the start and end of the selection to positions in the DOM.

    Has anyone else come across a solution? I can't really post my full code as it's part of an unfinished Xinha plugin, but I can post the section that I've written if it makes the problem clearer.

    Hope that makes sense, and thanks to everyone that tries to help

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See here:

    http://jorgenhorstink.nl/2006/03/11/...rnet-explorer/

    The code mentioned, which was harder to track down, and doesn't seem deliver on the claim that he implemented startContainer and endContainter is here:

    http://jorgenhorstink.nl/test/javasc...class.range.js


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •