|
Post by Schubaltz on Jun 10, 2007 15:34:18 GMT -5
Description: Breaks an element's hierarchy into an array (be wary of white space).
Syntax: fragmentElement(object)
function fragmentElement(a, b) { if(!b) b = []; for(var x = a.firstChild; x; x = x.nextSibling) { if(x.hasChildNodes()) { b.push(fragmentElement(x, [x])); continue; } b.push(x); } return b; }
Example: <html> <body> <div>Hello <b>world</b></div> </body> </html>
var d = document.getElementsByTagName("div")[0]; fragmentElement(d)[1][0] // bold element fragmentElement(d)[1][1] // "world" textnode
|
|