jQuery .has()定位不同的元素 [英] jQuery .has() Target Different Element
本文介绍了jQuery .has()定位不同的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jQuery上还很新,并且希望变得更好.我试图提出以下代码段:
I'm pretty new at jQuery and would like to get better. I tried to come up with this snippet of code:
$(document).ready(function(){
$("ul#result-list").has("div#boom")(
function() {
$("div.page-navigation").css("display", "none"));
});
});
如果ul#result-list具有div#boom,我正在尝试使div.page-navigation消失.到目前为止,尽管在网上搜索仍然没有运气.我远吗?谢谢你的帮助
I'm trying to make div.page-navigation disappear if ul#result-list has div#boom. No luck so far despite searching all over the web. Am I far off? Thanks for the hel
推荐答案
.has()
返回匹配的dom元素,而不是true或false布尔值.相反,请检查length
属性以确定#result-list
中是否存在div#boom
.
.has()
returns the matched dom elements, not a true or false boolean value. Instead, check the length
property to determine if div#boom
exists in #result-list
.
类似这样的东西:
$(document).ready(function() {
if ($("ul#result-list").has("div#boom").length) {
$("div.page-navigation").hide();
}
});
这篇关于jQuery .has()定位不同的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文