One option that occurred to me is to loop through all nodes in the div and count the words in the nodeValue if it's a text node, or otherwise loop through the element's sub-nodes if it has them. You could do this recursively and therefore find all text nodes within the DIV and its sub-elements.
The problem is this doesn't cover everything. Inputs and textareas have a value, not a nodeValue. You will want to ignore any "script" elements and perhaps others. Of course you can set up a list of exceptions and modify the algorithm a bit to allow for them.
It's meant to be a new thread, to ask for general ideas for how to best approach the problem. Sorry if it wasn't clear or if this is not the forum for such a broad and general question.
I saw someone talking about the challenges of making a word-count somewhere else on the web and thought I'd have a go at it but it has proven more complicated than I expected.
You must not worry about the text within the select options. From the DOM point of view they are not different form the texts within, say, a SPAN. But keep in mind that, in fact, in case of the SELECT elements, the text has no relevance. The value is important, not the text, because the value is submitted.
Thus, you problem regarding the values of the form's elements is meaningless. When you say that you want to search for the textNodes, then go searching for the textNodes. But the value is an attribute (or straight a JavaScript property) of an element, not a textNode. So, I don't see why do you mix different categories (textNodes with attributesNodes(or JS properties) within the same pot.
Bookmarks