Javascript 使用Jquery搜索和隐藏文本
我想使用jQuery查找一些文本,但它存在,我想隐藏它 因此,如果Javascript 使用Jquery搜索和隐藏文本,javascript,jquery,html,Javascript,Jquery,Html,我想使用jQuery查找一些文本,但它存在,我想隐藏它 因此,如果:Yes存在,则应将其隐藏 HTML: 上面的Jquery隐藏了整个div,而不仅仅是:Yes 试试这个: $('.hide此标记:contains(“Yes”)).hide(); 或 $('span.hide this tag:contains(“Yes”)).hide(); 或 $('div.listing_detail span.hide此标记:contains(“Yes”)).hide() 客厅:是 厨房:否您不能将选
:Yes
存在,则应将其隐藏
HTML:
上面的Jquery隐藏了整个div,而不仅仅是:Yes
试试这个:
$('.hide此标记:contains(“Yes”)).hide();
或
$('span.hide this tag:contains(“Yes”)).hide();
或
$('div.listing_detail span.hide此标记:contains(“Yes”)).hide()代码>
客厅:是
厨房:否
您不能将选择器传递给.hide()
。在对象上使用它:
$('.listing_detail:contains(“Yes”)).find('.hide this tag').hide()代码>
客厅:是
厨房:否
因为您正在添加。隐藏
在代码末尾,它正在选择所选元素(
),您需要的是如下内容:
if($('.listing_detail:contains("Yes")').length > 0){
$('.hide-this-tag').hide(); //After you checked that the "Yes" exsists, hide the tag.
}
$('.listing_detail:contains(“Yes”)).find('.hide this tag').hide()hide不允许您说出隐藏、查找元素的内容。隐藏此标记然后隐藏itI我在上一个问题中给出了这个答案,为什么不在我的答案下面发表评论,以便我可以进一步帮助您?
$('.listing_detail:contains("Yes")').hide('.hide-this-tag');
if($('.listing_detail:contains("Yes")').length > 0){
$('.hide-this-tag').hide(); //After you checked that the "Yes" exsists, hide the tag.
}