Get index of the current element.


/ Published in: jQuery
Save to your folder(s)

Quickly get the index of the current element. I find myself re-using this several times in a document, so I made a lil' function for it.


Copy this code and paste it in your HTML
  1. $.fn.getIndex = function(){
  2. var $p=$(this).parent().children();
  3. return $p.index(this);
  4. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.