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

  • Home
  • SEARCH
  • 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 1107091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:53:22+00:00 2026-05-17T01:53:22+00:00

I have HTML which looks something like this: <span id=text> <span class=segment id=first>some text</span>

  • 0

I have HTML which looks something like this:

<span id="text">
 <span class="segment" id="first">some text</span>
 <span class="segment" id="sec">bla bla</span>
</span>

and when user selects something, I want to identify which elements he had selected.
If, for example, user had selected “text bl” I need both “first” and “sec” elements.

For this, I tried using endContainer.nodeName but for every selected text I get parent element “text”. Is it posible to get child elements?

var selObj = window.getSelection();
    var selRange = selObj.getRangeAt(0);
    if(selRange!="") {
    var startName = selRange.startContainer.nodeName;
    var endName = selRange.endContainer.nodeName;
    alert(startName+" "+endName);
    }
  • 1 1 Answer
  • 1 View
  • 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-05-17T01:53:23+00:00Added an answer on May 17, 2026 at 1:53 am

    In your example, the problem is that the start and end container nodes for the selection are text nodes. You can get the container elements by checking the nodeType property:

    var startNode = selRange.startContainer;
    if (startNode.nodeType == 3) { // 3 is the node type for text nodes
        startNode = startNode.parentNode;
    }
    

    … and similar for the end container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a composite control which emits HTML that looks like this <span id=myControl>
I have a string of raw text which looks something like this: 1 .
I have a webpage with a form, which looks kinda like this: @using (Html.BeginForm(MyAction,
I have a html which looks roughly like this: <tr id=row> <td id=cell_1>Cell 1</td>
I am retrieving some data from the server which looks something like this: 1:some
I have a model that looks something like this: public class SampleModel { public
I have a file structure on my server that looks something like this: My
Ok so here is a problem, I have an html template which looks something
I have HTML which includes scripts in following order <script src=../static/js/jquery.js type=text/javascript> <script src=../static/js/bootstrap.js
I have a Javascript object that (very simplified) looks like this if('undefined' !== typeof(listCtrls)){

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.