开发者

Jquery next not finding the next div?

开发者 https://www.devze.com 2023-03-29 17:56 出处:网络
I have this HTML structure <imgwidth=\"25\" height=\"25\" src=/data/apple_logo.jpg alt=Chocolate />

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 returned but if i do this

$('.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 traverse down like the jquery closest method traverses up


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

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

jQuery Docs: nextAll()


siblings also work here

$('.cake_checkboxes:first').siblings('.quantity')
0

精彩评论

暂无评论...
验证码 换一张
取 消