Get the position(index) of an element in the parent
<p>I want to get the position of a an element in its parent. For example</p>

<pre><code>&lt;div&gt;
&lt;h2 class="one"&gt;A&lt;/h2&gt;
&lt;span&gt;Something&lt;/span&gt;
&lt;h2 class="two"&gt;B&lt;/h2&gt;
&lt;h2 class="three"&gt;C&lt;/h2&gt;
&lt;/div&gt;
</code></pre>

<p>Now suppose I get a reference of h2.two $('h2.two'); in an event. I want the position of this element relative to other h2's in the div. In this case it is 2. and please don't tell me I can get it through the classname, because there won't be these classnames. Its just for explanation.</p>

<p>NB: I want its position in the list of h2, basically in $('h2.two').parent().children('h2') not all elements</p>

<pre><code>function buildPath(element)
{
var Xpath,position=-1;
element=$(element);//Just in case;
Xpath=getTagName(element);
parent=element.parent();
console.log(parent.children(Xpath));

var position = element.siblings(Xpath).element.index(element);//I want the position here
Xpath="/"+Xpath+"["+position+"]";
    console.log(Xpath);
    console.log(getTagName(parent));
    if (getTagName(element)=='body')
    return Xpath;



 }
</code></pre>
