Reputation: 20001
I want to remove all anchor element where nested <span></span>
tag has only #
in it example
Remove This one
<a href="/search.aspx?search=something" class="keyword"><span class="tags">#</span></a>
Don't remove this one has some text with #
<a href="/search.aspx?search=something" class="keyword"><span class="tags">#Sometext</span></a>
Upvotes: 0
Views: 113
Reputation: 20636
Use filter()
function,
$('a').filter(function(){
return $.trim(this.text) === '#';
}).remove();
Or
$('a').filter(function () {
return $.trim($('span.tags',this).text()) === "#";
}).remove();
Upvotes: 1
Reputation: 428
Try this, if there is one or more than one .tags span, it should work
<script>
$(function(){
$('.tags').each(function(){
if( $(this).text() == "#" ){
$(this).parent().remove();
}
});
});
</script>
Upvotes: 1
Reputation: 18099
Try this:
$(".keyword").filter(function () {
return $.trim($(this).text()) == "#" ? true : false;
}).remove();
Demo: http://jsfiddle.net/GCu2D/663/
Upvotes: 1
Reputation: 25527
You can use filter to return the spans which has only #
text in it. Then find the parent anchor either by closest("a")
or parent()
$("span.tags").filter(function() {
return $(this).text().trim() == "#"
}).closest("a").remove();
Upvotes: 1