Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Description: Breaks an element's hierarchy into an array.

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





Last Edit: Apr 25, 2007 21:07:38 GMT by Aaron

newBookmarkLockedFalling