Getting index of clicked list element
<p>How can I get the index of the clicked element in a list?</p>

<p>So if I have the following list:</p>

<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
</ul>

<p>When I click <code>Third</code>, I would like to get the index <code>2</code>, provided the index starts with <code>0</code>.</p>

<p>With my code I only get <code>0</code>s:</p>

<p><strong>HTML:</strong></p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a href="#" class="listElem"&gt;First&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#" class="listElem"&gt;Second&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#" class="listElem"&gt;Third&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p><strong>JS:</strong></p>

<pre><code>$(".listElem").click(function(param) {
  console.log($(this).index());
});
</code></pre>

<p><a href="https://jsfiddle.net/y3v5fyxf/" rel="nofollow">Here is a fiddle</a>. </p>