I feel this should be an easy problem, but alas I find myself stuck. What I'm trying to do is set up a way so that every time you click on a cell on a table(or anywhere), it displays the parentNode of each element, essentially traversing up the DOM tree. I figured I would need to use elem.parentNode, but I'm stuck on the traversing part. Any gurus out there that can help me out, it would be greatly appreciated.
var element; //your clicked element
while(element.parentNode) {
//display, log or do what you want with element
element = element.parentNode;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With