How can I get the index of the current element in jQuery each() loop?
<p>I have a table, and some of them have input fields on which I need to run validation. After validation I am attaching a class <code>.mandatory</code> to the blank input fields. Now later on I need to loop through the <code>td</code>s which have <code>.mandatory</code> children and get the respective text/html from the respective <code>th</code> element of the table.  I thought the best bet is to find the index of the <code>td</code> and use that to get the correct <code>th</code>, but I don't know how to get the index of the <code>td</code> efficiently. I tried something like</p>

<pre><code>$('.mandatory').each(function(){
var ind = curr_tr.find('&gt;td').index($(this).closest('td'));//curr_tr is a reference to the current tr I am working with
var txt = $('th:eq('+ind+')').html();
})
</code></pre>

<p>But this seems inefficient, and won't work if some of the <code>.mandatory</code> fields are nested in further tables within the <code>td</code></p>
