JavaScript
Article

jQuery Get Index of Current Element

By Sam Deering

jQuery code snippet to get index of the current element. Good for those tasks that you use all the time and can simply put into a function for reuse.

$.fn.getIndex = function(){
	  var $p=$(this).parent().children();
    return $p.index(this);
}
  • Rafi

    Just modified it
    $.fn.getIndex = function(){
    var $sf = $(this), $p = $sf.parent().children();
    return $p.index($sf);
    };

Recommended
Sponsors
Get the latest in JavaScript, once a week, for free.