009820
009820

Reputation: 47

Specify the number of next?

I have multiple identical classes with the save properties so I cannot use nextUntil().

Let say I want to get the third one. How can I do that with the next() function? [index] does not work.

<div class="order-modifier-list"> </div>
<div class="order-modifier-list"> </div>
<div class="order-modifier-list"> </div>
<div class="order-modifier-list"> </div>
$(`.order-modifier-list`).next().find(`.order-modifier-list-item[item-id=${itemID}]`).attr('data-modifier-details')

Upvotes: 0

Views: 51

Answers (1)

Abdullah Danyal
Abdullah Danyal

Reputation: 1146

next() is not meant for getting the element by specifying index or number. The purpose of next is to get the next sibling of selected element. If you want to specify the number then use .eq(), which will return you a jQuery object of a specified element.

console.log($('.order-modifier-list').eq(2));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="order-modifier-list">1 </div>
<div class="order-modifier-list">2 </div>
<div class="order-modifier-list">3 </div>
<div class="order-modifier-list">4 </div>

Upvotes: 1

Related Questions