javascript - How to get clicked item index in jQuery collection? Not by index() -


i want index of clicked element

var $inputs = $("input"); $inputs.click(function() {     console.log($(this).index()) }); 

it works following structure div>(input+input+input)

but need case

div>input div>input div>input

inputs not siblings , same index each element. simplest way index?

check index within jquery element collection providing element argument , apply index() method on element collection.

var $inputs = $("input"); $inputs.click(function() {   console.log($inputs.index(this)); }); 

var $inputs = $("input");  $inputs.click(function() {    console.log($inputs.index(this));  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div>    <input>    <div>      <input>    </div>  </div>  <div>    <input>  </div>  <div>    <input>  </div>    <div>    <input>  </div>


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -