javascript - Get the index of div that has not a common class Jquery -


hello wanted index of div doesn't have class "already" code.

 $('#slotmachine #slotmachine2 div.combi:not(.already):first').index(); 

this html code.

<li id="slotmachine2"> <div class="combi already" data-id="17">john4654</div> <div class="combi already" data-id="18">john4015</div> <div class="combi" data-id="19">john1235</div> <div class="combi already" data-id="20">john0454</div> <div class="combi already" data-id="21">john1254</div> <div class="combi already" data-id="22">john0014</div> <div class="combi already" data-id="23">john1387</div> <div class="combi already" data-id="24">john2478</div> <div class="combi" data-id="25">john8475</div> <div class="combi already" data-id="26">john3597</div> <div class="combi" data-id="27">john7985</div> <div class="combi already" data-id="28">john3154</div> <div class="combi already" data-id="29">john9001</div> <div class="combi already" data-id="30">john0034</div> <div class="combi already" data-id="31">john0215</div> <div class="combi already" data-id="32">john3795</div> <div class="combi" data-id="33">john1567</div> <div class="combi already" data-id="34">john6523</div> <div class="combi already" data-id="35">john7956</div> <div class="combi" data-id="36">john1547</div> <div class="combi already" data-id="37">john6872</div> <div class="combi already" data-id="38">john3487</div> <div class="combi already" data-id="39">john8392</div> <div class="combi already" data-id="40">john3432</div> <div class="combi already" data-id="41">john3412</div> <div class="combi" data-id="42">john3413</div> <div class="combi already" data-id="43">john3419</div> <div class="combi already" data-id="44">john3423</div> <div class="combi" data-id="45">john3429</div> <div class="combi" data-id="46">john3427</div></li> 

the result zero. thank in advance masters!

you need specify based on collection need index.

// cache selector , based on index  var $col = $('#slotmachine #slotmachine2 div.combi');    console.log(    // element within collection find index    // , set `index()` methods argument    $col.index($col.filter(':not(.already):first'))  );    // code works if there siblings in html  console.log(    $('#slotmachine #slotmachine2 div.combi:not(.already):first').index()  )      // or can set selector in element  console.log(    $('#slotmachine #slotmachine2 div.combi:not(.already):first').index('#slotmachine #slotmachine2 div.combi')  )
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <ul id="slotmachine">    <li id="slotmachine2">      <div class="combi already" data-id="17">john4654</div>      <div class="combi already" data-id="18">john4015</div>      <div class="combi" data-id="19">john1235</div>      <div class="combi already" data-id="20">john0454</div>      <div class="combi already" data-id="21">john1254</div>      <div class="combi already" data-id="22">john0014</div>      <div class="combi already" data-id="23">john1387</div>      <div class="combi already" data-id="24">john2478</div>      <div class="combi" data-id="25">john8475</div>      <div class="combi already" data-id="26">john3597</div>      <div class="combi" data-id="27">john7985</div>      <div class="combi already" data-id="28">john3154</div>      <div class="combi already" data-id="29">john9001</div>      <div class="combi already" data-id="30">john0034</div>      <div class="combi already" data-id="31">john0215</div>      <div class="combi already" data-id="32">john3795</div>      <div class="combi" data-id="33">john1567</div>      <div class="combi already" data-id="34">john6523</div>      <div class="combi already" data-id="35">john7956</div>      <div class="combi" data-id="36">john1547</div>      <div class="combi already" data-id="37">john6872</div>      <div class="combi already" data-id="38">john3487</div>      <div class="combi already" data-id="39">john8392</div>      <div class="combi already" data-id="40">john3432</div>      <div class="combi already" data-id="41">john3412</div>      <div class="combi" data-id="42">john3413</div>      <div class="combi already" data-id="43">john3419</div>      <div class="combi already" data-id="44">john3423</div>      <div class="combi" data-id="45">john3429</div>      <div class="combi" data-id="46">john3427</div>    </li>  </ul>


check documentation of index() method more information.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -