[英]Prototype hide the div that has a specific link (<a href)
我有以下HTML:
<div> <a href="http://google.com"> Google </a></div>
我正在使用原型庫。 我需要隱藏帶有http://google.com鏈接的div。 謝謝。
在原型:
$$('div a[href="http://google.com"]').each(function (e) { Element.hide(e.parentNode); })
您可以使用CSS來執行此操作。
<div class="hideMe"> <a href="http://google.com"> Google </a></div>
然后在CSS中執行:
#hideMe {
display:none;
}
jQuery可以使用嗎?
如果是這樣,請使用以下代碼:
$(document).ready(function() {
$('a[href=http://www.google.com]').parent('div').hide();
});
如果父級不一定位於DOM的下一級,請使用.parents
代替:
$(document).ready(function() {
$('a[href=http://www.google.com]').parents('div').hide();
});
但是,這可能會影響樹中更高級別的div
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.