SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get selection range parent node in IE

    Hello all,

    I have a problem with cross browser combatibility which I have not found a solution on this forum after a search.

    For Netscape/Mozilla you can get the "parent node" of a selection using the following code...

    Code:
    var selection = window.getSelection();
    rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
    parentnode=rng.commonAncestorContainer;
    Unfortunately IE6 does not support/allow the rng.commonAncestorContainer command.

    Code:
    var selection = document.selection; 
    if (selection != null) {
    	rng = selection.createRange();
    }
    // Need the equivalent to rng.commonAncestorContainer Here
    Does anyone have any ideas on how to do this ?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A quick look at http://msdn.microsoft.com/workshop/a..._textrange.asp
    indicates that rng.parentElement should work, not that I've ever used it.


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
  •