Created
December 9, 2015 16:38
-
-
Save tomzmtl/12e620616853ddf2bbf2 to your computer and use it in GitHub Desktop.
JS stringToNodes
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
function stringToNodes ( string ) | |
{ | |
var div = document.createElement('div'); | |
div.innerHTML = string; | |
var allNodes = div.childNodes; | |
var nodes = []; | |
for ( var i = 0 ; i < allNodes.length ; i++ ) | |
{ | |
if ( allNodes[i].nodeType === Node.ELEMENT_NODE ) | |
{ | |
nodes.push(allNodes[i]); | |
} | |
} | |
return nodes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment