选择包含特定子项的父项
我在 html 中有这样的结构:
<ul id="resultlist">
<li>
<input type="hidden" value="idNumber" />
<dl>
...
</dl>
</li>
</ul>
jquery 中是否有一种单行方法可以根据子项查找
?目前我的代码中有这个来查找
但它很长://dynamic value
var idNumber = 2;
//finds input with value of 2
var hiddenInput = $('#resultList').find('input[value='+idNumber+']');
var listItem = hiddenInput.parent();
i have this structure in html:
<ul id="resultlist">
<li>
<input type="hidden" value="idNumber" />
<dl>
...
</dl>
</li>
</ul>
is there a one-liner method in jquery that finds the <li>
based on the child?
currently i have this in my code to find the <li>
but it's quite long:
//dynamic value
var idNumber = 2;
//finds input with value of 2
var hiddenInput = $('#resultList').find('input[value='+idNumber+']');
var listItem = hiddenInput.parent();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想要一句俏皮话,只需链接调用即可。
我还将
input
选择器带入第一个选择器中,以稍微缩短它,并且我还在属性值周围添加了缺失的引号。我想如果你真的想要的话,你可以使用非标准
:has()
选择器......If you want a one-liner, just chain the calls.
I also brought the
input
selector into the initial one to shorten it up a bit, and I also included the missing quotation marks around the attribute value.You could use the non-standard
:has()
selector I suppose if you really want it...