I need to get all parent elements of a specified element.
Take the following HTML as an example:
I only need to get the divs marked in blue. Since I couldn't find a way to just pluck these (if you know how this would simplify my process greately), I am doing:
This gives me every element in "main"... so how can I go through "containers" and get just the the ones I want (just the parents)?
I hope I've explained this clearly enough, if not let me know. Any thoughts/experience would greatly be appreciated!
X
Take the following HTML as an example:
Code:
<div id="main">
[blue]<div>[/blue]
<div>One</div>
<div>Two</div>
[blue]</div>[/blue]
[blue]<div>[/blue]
<div>One</div>
<div>Two</div>
[blue]</div>[/blue]
</div>
I only need to get the divs marked in blue. Since I couldn't find a way to just pluck these (if you know how this would simplify my process greately), I am doing:
Code:
var holder = document.getElementById("main");
var containers = holder.getElementsByTagName("*");
This gives me every element in "main"... so how can I go through "containers" and get just the the ones I want (just the parents)?
I hope I've explained this clearly enough, if not let me know. Any thoughts/experience would greatly be appreciated!
X