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 8313667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:34:06+00:00 2026-06-08T20:34:06+00:00

In a js function, I want to obtain all Nodes(HTML elements) that are part

  • 0

In a js function, I want to obtain all Nodes(HTML elements) that are part of the content in a web page, when the content has been selected by the user.

Now, I understand that window.getSelection() will give me a selection object. Also, this selection object has to be converted into a range object, before I can obtain the list of nodes(HTML elements) that are part of that selection.

How do I obtain the range object? From what i read, different browsers have different implementations of range objects…Initially, I will use this js function only in Google Chrome…So code should work perfectly in Google Chrome… but I do want that the code works across all/most new versions of Google Chrome… The code may be JS or pure Jquery.

One more question– do I have to use a js library like “Rangy”- http://code.google.com/p/rangy/ for this purpose? Or can this be achieved using pure js or jquery code?

  • 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-08T20:34:09+00:00Added an answer on June 8, 2026 at 8:34 pm

    Apart from IE < 9, all major browsers implement the same standards for Selection and Range and have done for years. There are some differences but the APIs are the same. If you’re not bothered about IE < 9 then you really don’t need to use Rangy (it’s around 40KB before gzipping), although it does have a convenient method for getting nodes that you may find helpful.

    To get the nodes within the selection, you can get the selected range like this:

    var sel = window.getSelection();
    if (sel.rangeCount > 0) {
        var range = sel.getRangeAt(0);
    }
    

    To get the nodes from the range, you could use the code from this answer. If you used Rangy, it would be

    var sel = rangy.getSelection();
    if (sel.rangeCount > 0) {
        var range = sel.getRangeAt(0);
        var nodes = range.getNodes();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to obtain the exact details for the item on a web page
I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I want to specify in a header file that the input to a function
I'd like to define a helper function that has the ability to modify a
I want to retrieve property value in jquery function and want to set it
I have one r function i want to run it automatically(scheduling) after every predefined
There is a loop in the function I want to modify: foreach ( $form_fields
I've got a simple js/jquery function I want to run when the form is
I have a problem returning data back to the function I want it returned
This is a mystery.. in my controller Add function i want to enter the

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.