Created
May 19, 2015 19:11
-
-
Save marcelaraujo/acf87a7842dfaddb1814 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function wrapSpan(node, index) { | |
| if(node.nodeName === '#text') { | |
| var text = node.textContent; | |
| var s = document.createElement('span'); | |
| s.textContent = text; | |
| node.parentElement.insertBefore(s, node.parentElement.childNodes[index]); | |
| node.remove(); | |
| } else { | |
| var length = node.childNodes.length; | |
| // childNodes is a collection, not an array. :-/ | |
| for(var i = 0; i < length; i++) | |
| wrapSpan(node.childNodes[i], i); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment