jQuery next找不到下一个div? [英] Jquery next not finding the next div?

查看:104
本文介绍了jQuery next找不到下一个div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个HTML结构

<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">
......

如果我这样做

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

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

我得到一个空值,但如果我这样做

I get an empty value returned but if i do this

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

我得到了我需要的div ...关于错误的任何想法,或者是否有像jQuery这样的遍历方法最近的方法向上移动

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() 仅返回DOM中的下一个元素(如果它与选择器匹配),否则返回和空对象.因此,您唯一可以使用next()搜索的是<label>.改用它:

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文档: nextAll()

jQuery Docs: nextAll()

这篇关于jQuery next找不到下一个div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆