我想使用jQuery查找一些文本,并且存在它想要隐藏它。
因此,如果: Yes
存在,则应将其隐藏。
HTML:
<div class="listing_detail col-md-4"><strong>Living Room:</strong><span class="hide-this-tag"> Yes</span></div>
<div class="listing_detail col-md-4"><strong>Kitchen:</strong><span class="hide-this-tag"> No</span></div>
jQuery:
$('.listing_detail:contains("Yes")').hide('.hide-this-tag');
上面的Jquery隐藏了整个div,而不仅仅是 : Yes
您不能将选择器传递给.hide()
。您在对象上使用它:
$('.listing_detail:contains("Yes")').find('.hide-this-tag').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="listing_detail col-md-4"><strong>Living Room:</strong><span class="hide-this-tag"> Yes</span></div>
<div class="listing_detail col-md-4"><strong>Kitchen:</strong><span class="hide-this-tag"> No</span></div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句