0

For a chrome extension I want to ouput every word of a webpage on a newline. I found code which can provide me with all the text on a webpage:

range = document.createRange();
range.setStart(document.body,0);
range.setEnd(document.body,document.body.childNodes.length);
words = range.toString();

the variable words contains all the text of the webpage. But as far as I know, all the markup is gone because I am not handling any nodes any more, but just plain text. How would I go through a range word by word and be able to tell which css-properties (for example font-size) is used? And weather the word is in someway part of a <h1> tag?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Nicky Smits
  • 2,980
  • 4
  • 20
  • 27
  • 1
    You wouldn't, if you need the markup and styles, don't get a text range ? – adeneo Mar 20 '14 at 00:08
  • 1
    Use something like [this](http://stackoverflow.com/a/4399718/240443) to get all the text nodes, then you can see where they are in the DOM. – Amadan Mar 20 '14 at 00:10

0 Answers0