Let’s suppose I read the contents of a text node like so:
s = current_node.getSelection().anchorNode.nodeValue;
What is the best way to count how many characters are displayed on the webpage due to this one node? I know that for example would be displayed as a literal string so no need to look for these. Is all I need to do then to count several spaces in a row as one character? Is there anything else I need to look out for?
You can ask the browser for the text version of what’s in the node like this:
This will have already converted entities to their regular characters and will not include any HTML tags. Multiple spaces will come out as multiple spaces though – that’s just how this function in the browser works. If you were pretty sure that there were no multiple
sequences in the HTML, you could collapse the multiple spaces like this:Example here: http://jsfiddle.net/jfriend00/FpsGq/