I have the following HTML markup:
<body>
<div class="wrapper">
<div class="head">
<p class="title">title</p>
<a href="#" class="logo"></a>
</div>
</div>
</body
I need to get something like the following - the "A" element with class "logo" is the seconde childNode of the div element with class "head". The div element with class "head" is the first childNode of the div element with class "wrapper", the div element with class "wrapper" is the first childNode of body. Then I would get the location of the link with class "logo" as follows:
var a = [1, 1, 2]
So, if I go in the opposite direction using the array above, I will find the link with class "logo" in the DOM starting from the body element. Could anybody tell me how can this be achieved with JavaScript?
Thanks in advance.
childNodescollection can therefore be more difficult than you currently think. These days however there is achildrencollection that only contains element child nodes, so depending on your needs you might consider to use that collection..childNodesbased on HTML.