amirhossein.fa amirhossein.fa - 2 months ago 6
jQuery Question

We have div's list of the same classes. I want remove one of those which has element with the special class

I want to remove

<div class="chrg-item>
who has image whit this class
.gr

but this code not work!!

$('.chrg-item').hasClass('.gr').remove()

<div class="chrg-item">
<img src="images/thumbs/1.jpg">
</div>
<div class="chrg-item">
<img class="gr" src="images/thumbs/1.jpg">
</div>
<div class="chrg-item">
<img src="images/thumbs/1.jpg">
</div>

Answer

You can also use the code below:

$('.gr').closest('.chrg-item').remove();