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

use .index( element )

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

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -