I asked a similar question yesterday ( Hide element if it contains specific text )
I have since tried to adapt the code suggested by dystroy to hide a DIV on another page.
This is the page HTML:
<div class="ct_pl_product_price">
<a class="ct_pl_product_link" href="/link/to/item">£0.00</a>
</div>
As before, I would like to hide the "ct_pl_product_price" DIV if it contains £0.00
This is the script I have tried using:
$(document).ready(function(){
$(".ct_pl_product_price").filter(function(){
return $(this).clone().find('.ct_pl_product_link').remove().end().text().trim()=="0.00"
}).hide()
});
I think that makes sense (if I've interpreted dystroys' code correctly) but it doesn't appear to work.
Any ideas?
你可以使用:contains
在这种情况下:contains
选择器:
$('.ct_pl_product_price:contains("£0.00")').hide()
You can use the :contains
selector:
$('.ct_pl_product_price:contains("0.00")').hide();
Or you can use filter
, modifying the logic:
$(".ct_pl_product_price").filter(function(){
return $(this).text().indexOf('0.00') != -1;
}).hide()
Note that filter()
will be slightly faster.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.