我昨天问过类似的问题(Hide element if it contains specific text)
从那以后,我尝试修改 dystroy 建议的代码以在另一个页面上隐藏一个 DIV。
这是页面 HTML:
<div class="ct_pl_product_price">
<a class="ct_pl_product_link" href="/link/to/item">£0.00</a>
</div>
和以前一样,如果“ct_pl_product_price”DIV 包含 £0.00,我想隐藏它
这是我尝试使用的脚本:
$(document).ready(function(){
$(".ct_pl_product_price").filter(function(){
return $(this).clone().find('.ct_pl_product_link').remove().end().text().trim()=="0.00"
}).hide()
});
我认为这是有道理的(如果我正确解释了 dystroys 的代码)但它似乎不起作用。
有什么想法吗?
最佳答案
在这种情况下,您可以使用 :contains
选择器:
$('.ct_pl_product_price:contains("£0.00")').hide()
关于javascript - 隐藏包含特定文本的 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24953458/