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


Quick Links:


newBookmarkLockedFalling

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Description: A couple quick functions to save you the hassle of repeating parentNode and firstChild continuously.

Syntax:
getChildOf(object, integer)
getParentOf(object, integer)

function getChildOf(a, b) {
while(!a.data && a.firstChild && b > 0)
a = a.firstChild, b --;
return a;
}
function getParentOf(a, b) {
while(a.parentNode && b > 0)
a = a.parentNode, b --;
return a;
}


Example:
<html>
<body><div><span><b>hey</b></span></div></body>
</html>

var d = document.body;
alert(getChildOf(d, 4).data) // alert "hey"





Mancer

Mancer Avatar

**
Official Member

95


April 2007
very nice, another great piece in the library
I'm starting this revolution: This is my sandbox, y'all just dig'n.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
These are just kinda random, but nice functions. :P Maybe give a brief explanation of the second parameter though. Some people might not be what it's for.

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
cddude229 said:
These are just kinda random, but nice functions. :P Maybe give a brief explanation of the second parameter though. Some people might not be what it's for.


Eh, I wouldn't have added these if I hadn't written the fragmentElement() function along with them.

(¯`•DregondRahl•._)

(¯`•DregondRahl•._) Avatar
Remanifesting-Eternal

***
Dedicated Member

239


September 2006
How does it handle white spaces ?




Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
It just reiterates .firstChild. I'm not passing anything special through the function. It handle whitespace like the actual method would.

newBookmarkLockedFalling