Created
July 9, 2015 18:30
-
-
Save mhgbrown/f9a692b3a6135c11f775 to your computer and use it in GitHub Desktop.
retrieve all text nodes which are not made of space characters using TreeWalker API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrieve all text nodes which are not | |
* made of space characters. | |
* @return {Array} A collection of text nodes | |
**/ | |
var getTextNodes = function() { | |
var walker = document.createTreeWalker( | |
this.rootElement, | |
NodeFilter.SHOW_TEXT, | |
null, | |
false | |
), | |
node = walker.nextNode(), | |
textNodes = []; | |
while(node) { | |
if(!this.REGEXP_SPACES.test(node.nodeValue)) { | |
textNodes.push(node); | |
} | |
node = walker.nextNode(); | |
} | |
return textNodes; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment