Reputation: 4212
I have a div which basically looks like this:
<div class="wrapper">
<img src="#" />
<a href="#" class="link"> SomeText </a>
<a href="#" class="provider"> SomeText </a>
<div class="description">Text Text Text</div>
</div>
As you can see the text within .provider
is the same as in .link
My question is: How do I remove the whole div (.wrapper) if there is such a duplicate of text? Please note the text is not set, it could be anything, so therefore its a var:
var text = $('.provider').text();
$('.wrapper a:contains(text)').remove();
This is one of my many attempt with no luck.
Upvotes: 2
Views: 822
Reputation: 38
var text = $('.provider').text();
$('.wrapper a:contains('+text+')').parent().remove();
may be this one.
Upvotes: 1
Reputation: 144669
$('.wrapper').filter(function(){
var a = $('a.link', this).text(), b = $('a.provider', this).text();
return $.trim(a) === $.trim(b)
}).remove()
Upvotes: 1
Reputation: 474
this should do the job:
$('div.wrapper').each(function() {
if($('.link', this).text() == $('.provider', this).text())
$(this).remove();
});
(example: http://jsfiddle.net/8b655/)
Upvotes: 5