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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:13:45+00:00 2026-06-16T00:13:45+00:00

OK, I have a little function walking the tree like this: function walkTree(node, func,

  • 0

OK, I have a little function walking the tree like this:

function walkTree(node, func, args) {
    func(node, args);
    node = node.firstChild;
    while (node) {
        walkTree(node, func, args);
        node = node.nextSibling;
    }
}

And another function that would pick up only the text nodes like so:

function selectTextNodes(node, nodes) {
    if (node instanceof Text) {
        nodes.push(node);
    }
}

And finally, using both:

texts = [];
walkTree(body, selectTextNodes, texts);

However, it doesn’t fill the list at all!

If I were to modify the test as to use Node.nodeType it would work:

function selectTextNodes(node, nodes) {
    if (node.nodeType == Node.TEXT_NODE) {
        nodes.push(node);
    }
}

On the other hand, in the console it works both ways:

t = window.document.createTextNode("test");
r = (t.nodeType == Node.TEXT_NODE) && (t instanceof Text);

That is, r is true.

Note that, all functions are nested inside another function that receives the body variable. In my case, this is the contentDocument.body of an iframe. There is no x-domain restriction being applied.

Any idea what’s going on?

  • 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-16T00:13:46+00:00Added an answer on June 16, 2026 at 12:13 am

    There are different Text interfaces in the different windows. So, if you have a DOM node from your iframe document, it is not an instanceof window.Text, but an instanceof iframe.contentWindow.Text. Afaik, also the availability of the Text interface as a Javascript object is non-standard.

    That is why you just should check the nodeType of the elements. But notice that (older?) IE does not support the TEXT_NODE constant on Node, so you will either need to compare with 3 or assign that value as a polyfill to Node.TEXT_NODE.

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

Sidebar

Related Questions

I have an awesome little function that looks like this: def verbose_print(message, *args, **kwargs):
I have this function in C# to convert a little endian byte array to
I have this little function here: public Activity getRootActivity() { Activity a = this;
I have little knowledge on oracle. I tried to create a function like below.
For example, if I have this little function: string lw(int a, int b) {
I have this little function : $('.chrnumberpickerDiv select').change(function(){ var sel = $(this), value =
So I have this neat little javascript function that I'm using to print text
I have this little function to filter my array by keys: private function filterMyArray(
I have actually this little function working as supposed: Function createAttached(strTable As String, strPath
Hi i have this little plugin installed: (function($) { $.fn.tagfield = function(options) { if

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.