Manny Calavera
Manny Calavera

Reputation: 6873

Prototype hide the div that has a specific link (<a href)

I have the following 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. Thank you.

Upvotes: 1

Views: 1628

Answers (3)

Gandalf
Gandalf

Reputation: 9855

You could use a CSS to do this.

<div class="hideMe"> <a href="http://google.com"> Google </a></div>

and then in a CSS do :

#hideMe {
  display:none;
}

Upvotes: 1

Ayman Hourieh
Ayman Hourieh

Reputation: 137266

In Prototype:

$$('div a[href="http://google.com"]').each(function (e) { Element.hide(e.parentNode); })

Upvotes: 3

Tomas Aschan
Tomas Aschan

Reputation: 60644

Is jQuery available to you?

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:

$(document).ready(function() {
    $('a[href=http://www.google.com]').parents('div').hide();
});

However that might affect divs on an even higher level in the tree.

Upvotes: 0

Related Questions