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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:21:36+00:00 2026-06-12T10:21:36+00:00

I want to generate an array of nodes in a page, which will have

  • 0

I want to generate an array of nodes in a page, which will have all of the possible startContainers for Ranges.

I’ve tried to use a treeWalker but it gives me a node which is deeper than the actual startContainer node, for example:

<p>For those keeping count at home, by the way, the <a target="_blank" href="http://msdn.microsoft.com/en-US/windows/apps/br229516.aspx">Windows 8 Developer Preview site</a> still happily talks about "Metro style app development,"; even though <a target="_blank" href="http://www.istartedsomething.com/20120816/microsofts-new-rule-no-metro-named-apps/">rumor has it</a> that Microsoft is now banning all apps with the word "Metro" in their name from the Windows Store.</p>

(Taken from techcrunch.com)

So my tree walker returns the following:

['For those keeping count at home, by the way, the ','Windows 8 Developer Preview site',' still happily talks about "Metro style app development,"; even though ','rumor has it',' that Microsoft is now banning all apps with the word "Metro" in their name from the Windows Store.']

(Split)

But when I try and get the following:
window.getSelection().getRangeAt(0).startContainer.textContent
I get:

['For those keeping count at home, by the way, the Windows 8 Developer Preview site still happily talks about "Metro style app development,"; even though rumor has it that Microsoft is now banning all apps with the word "Metro" in their name from the Windows Store.']

(Not split)

Why isn’t the startContainer more deep (split)? like the treeWalker is?

Here is the code of the tree walker:

var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ALL, function(node) {
    if (node.nodeType == 3) {
        return NodeFilter.FILTER_ACCEPT;
    } else if (node.offsetWidth && node.offsetHeight) {
        return NodeFilter.FILTER_SKIP;
    } else {
        return NodeFilter.FILTER_REJECT;
    }
}, false);
  • 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-12T10:21:37+00:00Added an answer on June 12, 2026 at 10:21 am

    I imagine you’ve selected the whole of an element, such as one of the links. The crucial fact is that the startContainer of a range obtained from the selection is not guaranteed to be a text node.

    If a whole element is selected, some browsers will report the selection as spanning the children of the element’s parent node. For a selection spanning one of a number of consecutive images, for example, it’s essential. Imagine the selection encompasses just the second image in the HTML below:

    <div><img src="1.jpg"><img src="2.jpg"><img src="3.jpg"></div>
    

    In this case the selected range will have startContainer and endContainer properties that refer to the <div> element and startOffset 1 and endOffset 2, representing the range stretching between the children at indexes 1 and 2 in the container’s childNodes property.

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

Sidebar

Related Questions

I have an array of 27 elements, and I don't want to generate all
i have two numbers 1,2 in one array.Now i want to generate all the
I want to generate the array $result_array. There is no error at the page,
Let's say I have a class of 30 students and want generate every possible
I have a very long list in a numpy.array . I want to generate
I have a function that I want to generate an array with. The format
I want generate array of all locales for all International currencies. I want to
I have source array, and I want to generate new array from the source
I want to generate the lines, which I get from an array in 3D.
I need to generate byte array for TripleDES encryption. I don't want to use

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.