JavaScript
Article
By Sam Deering

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.

--ADVERTISEMENT--

$.fn.getIndex = function(){
	  var $p=$(this).parent().children();
    return $p.index(this);
}
Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account