Is there any way to get the collection of all textNode
objects within a document?
getElementsByTagName()
works great for Elements, but
I know you specifically asked for a collection, but if you just meant that informally and didn't care if they were all joined together into one big string, you can use:
var allTextAsString = document.documentElement.textContent || document.documentElement.innerText;
...with the first item being the DOM3 standard approach. Note however that innerText
appears to exclude script or style tag contents in implementations that support it (at least IE and Chrome) while textContent
includes them (in Firefox and Chrome).