Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery index of item in selector

Tags:

jquery

this is pseudo code

  var index_of_myid = $('.selection').indexOf($('#myid));

not sure if this is right is this possible if you can understand what I'm trying to do

EDIT

 <div>
    <div class="selector"></div>
 </div>
 <div>
    <div class="selector"></div>
 </div>
 <div>
    <div class="selector" id="myid"></div>
 </div>
 <div>
    <div class="selector" id="myid2"></div>
 </div>

I just need to know what number selector is the myid

like image 271
mcgrailm Avatar asked Aug 17 '10 01:08

mcgrailm


1 Answers

Surely you mean to be using jQuery's index as opposed to the indexOf JS string method:

var index_of_myid = $('.selection').index($('#myid'));

See http://api.jquery.com/index/

like image 111
karim79 Avatar answered Oct 01 '22 02:10

karim79