Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  63] [ 4]  / answers: 1 / hits: 48639  / 13 Years ago, wed, january 4, 2012, 12:00:00

I mean an array of them. That is a chain from top HTML to destination element including the element itself.



for example for element <A> it would be:



[HTML, BODY, DIV, DIV, P, SPAN, A]

More From » dom

 Answers
0

A little shorter (and safer, since target may not be found):



var a = document.getElementById(target);
var els = [];
while (a) {
els.unshift(a);
a = a.parentNode;
}

[#88238] Tuesday, January 3, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorw

Total Points: 484
Total Questions: 120
Total Answers: 107

Location: Faroe Islands
Member since Thu, Apr 8, 2021
3 Years ago
;