Jquery next not find next div?

I have this HTML structure

<img width="25" height="25" src=/data/apple_logo.jpg alt=Chocolate /> <input class="cake_checkboxes" style="vertical-align: bottom;" type="checkbox" name="option[232][]" value="23" id="option-value-23" /> <label for="option-value-23"> Chocolate</label> <br /> <div style='display:none;' class="quantity"> ...... 

If i do

 $('.cake_checkboxes:first').next('div') 

or

 $('.cake_checkboxes:first').next('.quantity') 

I get an empty value, but if I do

 $('.cake_checkboxes:first').next().next().next() 

I get the div I need ... any ideas on what is wrong, or if there is a way to turn down how the jquery closest moves

+6
source share
2 answers

next() returns only the next element in the DOM if it matches the selector, otherwise it returns and the object is empty. So the only thing you could use next() is <label> . Use this instead:

 $('.cake_checkboxes:first').nextAll('.quantity').first() 

jQuery Docs: nextAll()

+22
source
Brothers and sisters also work here.
 $('.cake_checkboxes:first').siblings('.quantity') 
+3
source

Source: https://habr.com/ru/post/895630/


All Articles