jQuery: element position/index of the same tagname
<p>Here is an example element</p>

<pre><code>&lt;div id="random_parent"&gt;
  &lt;h1&gt;&lt;/h1&gt;
  &lt;h2&gt;&lt;/h2&gt;
  &lt;h2&gt;&lt;/h2&gt;
  &lt;h1 class="target"&gt;&lt;/h1&gt;
  &lt;h2&gt;&lt;/h2&gt;
  &lt;h2 class="target"&gt;&lt;/h2&gt;
  &lt;h2&gt;&lt;/h2&gt;
&lt;/div&gt;
</code></pre>

<p>Now I create these two jQuery objects:</p>

<pre><code>var j_h1 = $("#random_parent h1.target");
var j_h2 = $("#random_parent h2.target");
</code></pre>

<p>I need a function, that outputs the position/index of an element inside of a parent class. Example:</p>

<pre><code>posElement(j_h1) == 2 // The second child with the tagname h1
posElement(j_h2) == 4 // The fourth child with the tagname h2
</code></pre>

<p>How do I write such a function? Thank You</p>