javascript - Get index of jquery object within another jquery object -
suppose
<div class='foo' id='a'></div> <div class='foo' id='b'></div> <div class='foo' id='c'></div> var foos = $('.foo');
we can first foo if want
var myfoo = $(foos.get(0));
now have myfoo, how can opposite index?
var index = foos.getindexof(myfoo);
if .index() called on collection of elements , dom element or jquery object passed in, .index() returns integer indicating position of passed element relative original collection.
var foos = $('.foo'); var myfoo = $(foos.get(0)); console.log(foos.index(myfoo)); <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class='foo' id='a'></div> <div class='foo' id='b'></div> <div class='foo' id='c'></div>
Comments
Post a Comment