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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:40:32+00:00 2026-05-31T01:40:32+00:00

I am using javascript and want to traverse the HTML tree, getting all the

  • 0

I am using javascript and want to traverse the HTML tree, getting all the text as it appears to the user. However, I am losing spacing information.

Let’s say I have two docs:

<html>XXX<p>YY    YY</p><html>

<html>XXX<p>YY&nbsp;&nbsp;&nbsp;YY</p><html>

The first one will appear with 1 space between the Ys. The second will have 3 spaces. However, if I traverse the tree and, for each #text node, use:

text = node.nodeValue;

then the text for both nodes will have 3 spaces. I no longer know which one has the “real” nbsp spaces. I can use node.innerHTML for the p elements, which will show the nbsp, but I don’t think that I can use innerHTML to get just the XXX text (without some kind of text subtraction).

I could just get innerHTML of the whole document and parse that. However, I also need to get the computed style of each element, which I am going to get using

window.getComputedStyle(theElement).getPropertyValue("text-align");

So, I will be traversing each node. Also, innerHTML shows the source as is, while traversing the nodes “fixes” html errors, adding end tags, etc. That’s a good thing and something I’d like to keep.

  • 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-05-31T01:40:33+00:00Added an answer on May 31, 2026 at 1:40 am

    What if you test by charCode? I believe a regular space is 32, while &nbsp; is 160.

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

Sidebar

Related Questions

I want to find all #tags in a piece of text (using javascript) and
Suppose a HTML document has a iframe. Using javascript,I want to detect ,on load
i want to enable facebox jquery using javascript. here in normal html <a href=stairs.jpg
I want to add some style to head tag in html page using javascript.
I want to split certain text using JavaScript. The text looks like: 9:30 pm
I want to create inline SVG graphics using Javascript. However, it seems like createElementNS
I want prevent user to select dropdown list items using javascript methods. Is there
I want to go through all the elements on a page using Javascript and
i want to send a json string from a html webpage using javascript to
I want to hide this warning div using javascript inside it. I'm i getting

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.