Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:32:29+00:00 2026-06-09T02:32:29+00:00

Here is my HTML: <ul contenteditable> <li>Hi there 1</li> <li>HI 2 2 2 2

  • 0

Here is my HTML:

<ul contenteditable>
  <li>Hi there 1</li>
  <li>HI 2 2 2 2 2</li>
  <ul><li>hi 3</li></ul> <!-- I know it's invalid, it's what document.execCommand('indent') yields -->
  <li> hi 4 hi there people 4 here now </li>
</ul>

(you can see it at http://www.webdevout.net/test?06&raw for the next week)

I am attempting to determine whether the currently selected text (in IE8) is within one LI or spans multiple LIs. When I select the entirety of LI’s one and two, then enter the following into the console document.selection.createRange().parentElement().innerHTML, the contents of only the second LI (HI 2 2 2 2 2 2) is returned.

Why is TextRange.parentElement returning the final element in the range rather than the parent of the entire range?

The docs say “If the text range spans text in more than one element, this method returns the smallest element that encloses all the elements.” My ultimate goal is to determine whether more than one LI is selected; I thought “check if parentElement().nodeName.toUppercase === “LI”” would do it but I can’t do this if parentElement() isn’t returning the parentElement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:32:31+00:00Added an answer on June 9, 2026 at 2:32 am

    I’ve seen this kind of thing before and it’s a bug in IE. The workaround I use in my Rangy library is to use the innermost common ancestor of three elements:

    • the parentElement() of the TextRange
    • the parentElement() of the TextRange after calling collapse(true)
    • the parentElement() of the TextRange after calling collapse(false)

    Here’s the code from Rangy:

    /*
     This is a workaround for a bug where IE returns the wrong container
     element from the TextRange's parentElement() method. For example,
     in the following (where pipes denote the selection boundaries):
    
     <ul id="ul"><li id="a">| a </li><li id="b"> b |</li></ul>
    
     var range = document.selection.createRange();
     alert(range.parentElement().id); // Should alert "ul" but alerts "b"
    
     This method returns the common ancestor node of the following:
     - the parentElement() of the textRange
     - the parentElement() of the textRange after calling collapse(true)
     - the parentElement() of the textRange after calling collapse(false)
     */
    var getTextRangeContainerElement = function(textRange) {
        var parentEl = textRange.parentElement();
    
        var range = textRange.duplicate();
        range.collapse(true);
        var startEl = range.parentElement();
    
        range = textRange.duplicate();
        range.collapse(false);
        var endEl = range.parentElement();
    
        var startEndContainer = (startEl == endEl) ?
            startEl : dom.getCommonAncestor(startEl, endEl);
    
        return startEndContainer == parentEl ?
            startEndContainer : dom.getCommonAncestor(parentEl, startEndContainer);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the exact code seen here: http://gazpo.com/downloads/tutorials/html5/contentEditable/ As you can see, when
Fiddle is here - http://jsfiddle.net/ashwyn/a45ha/ HTML here - <div class=parent> <div class=a>Class A</div> <div
http://subzerostudio.com/temp/verticalscroller/scroller/scroller.html Here's the fullscreen vertical scrolling site.. I've only tested it in FF so
I am trying to follow Trees tutorial at: http://cslibrary.stanford.edu/110/BinaryTrees.html Here is the code I
I'm trying to match the hover over the contenteditible section here: http://html5demos.com/contenteditable This is
How can I float this text here: HTML: <div id=rightSide> <legend>Note:</legend> <p> If selecting
Here is the script as I am using it now: <?php echo '<html><body>'; //
I am using a html minifier, which can be found here: HTML minify The
How we can get the content present in contentEditable in html format in PHP
Consider the following example: ( live demo here ) HTML: <div class=board> <div class=row>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.