我昨天(Hide element if it contains specific text)問過類似的問題隱藏DIV,如果它包含特定文本
我曾經試圖去適應由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的代碼),但它似乎沒有工作。
任何想法?
謝謝,這非常有幫助。出於興趣,我不認爲你可以解釋爲什麼其他代碼不起作用? – user3220812
@ user3220812對於一個開始,你錯過了「£」在你的公式 – Banana
@ user3220812:因爲,find('。ct_pl_product_link')。remove()'刪除其中的文本。 –