jQuery - get current index Norlihazmey Ghazali

http://stackoverflow.com/questions/34057079/how-can-i-get-the-current-index-of-an-element-with-a-class-jquery/34057194#34057194

by Norlihazmey Ghazali

HTML

<input type="text" value="a" class="hello"/>
<input type="text" value="b" class="hello"/>
<div>
  <div>
     <input type="text" value="d" class="hello"/>
  </div>
 
</div>
<input type="text" value="e" class="hello"/>

JavaScript

$('input').click(function () {
  alert('Using $(this).index(): ' + $(this).index())
  alert('Using $(\'.hello\').index($(this)): ' +$('.hello').index($(this)))
})