[英]Prototype hide the div that has a specific link (<a href)
I have the following HTML: 我有以下HTML:
<div> <a href="http://google.com"> Google </a></div>
I am using prototype library. 我正在使用原型库。 I need to hide the div that has the link http://google.com with it. 我需要隐藏带有http://google.com链接的div。 Thank you. 谢谢。
在原型:
$$('div a[href="http://google.com"]').each(function (e) { Element.hide(e.parentNode); })
You could use a CSS to do this. 您可以使用CSS来执行此操作。
<div class="hideMe"> <a href="http://google.com"> Google </a></div>
and then in a CSS do : 然后在CSS中执行:
#hideMe {
display:none;
}
Is jQuery available to you? jQuery可以使用吗?
If so, use the following code: 如果是这样,请使用以下代码:
$(document).ready(function() {
$('a[href=http://www.google.com]').parent('div').hide();
});
If the parent is not necessarily on the immediate next level in the DOM, use .parents
instead: 如果父级不一定位于DOM的下一级,请使用.parents
代替:
$(document).ready(function() {
$('a[href=http://www.google.com]').parents('div').hide();
});
However that might affect div
s on an even higher level in the tree. 但是,这可能会影响树中更高级别的div
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.