I am trying to remove an element in jquery if the contents are equal to a variable set in jquery. In this example I am trying to remove .sub3 as the contents are equal to the variable set.
<div class="sub1">
<a href="/large.jpg" class="group1 cboxElement">
<img border="0" alt="" src="/thumb.jpg">
</a>
</div>
<div class="sub2">
<a href="/029-large.jpg" class="group1 cboxElement">
<img border="0" alt="" src="/029-thumb.jpg">
</a>
</div>
<div class="sub3">
<a href="" class="group1 cboxElement"></a>
</div>
The Jquery I have come up with just removes the whole element regardless
var nopic = <a class="group1 cboxElement" href=""></a>;
if($.trim($(".sub1").text()) == nopic) {
$(".sub1").remove();
}
if($.trim($(".sub2").text()) == nopic) {
$(".sub2").remove();
}
if($.trim($(".sub3").text()) == nopic) {
$(".sub3").remove();
}
Thanks for any pointers!
One line, simple case that works on all empty links:
$('div[class^="sub"] a.group1.cboxElement[href=""]').parent('div').remove()