[jQuery] jQuery nodes traversing

[jQuery] jQuery nodes traversing


Hi,
Consider the following html :
<div id="main">
<div>
<p/>
<p/>


<h2> target node </h2>



</div>
</div>
Starting from the h2 node, I want to find its closest parent with an
id, in this case the div with id="main". I also want to store the
index position of all of the parents of the target. In this case that
would be 0 (for the div right under "main") and 2 (for the third

)
How can I do that using jQuery ? I hope what I ask is clear enough.