🤯 New: Coding Assessments Practice your skills on real-world programming challenges

jQuery Get Index of Current Element

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);