Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all elements with the same class

So I have a system were the user of the site can create div's and all these div's get different class names, with all these div's there will also be created a delete button with the same class. How do you remove the button and the div with the same class on click on the button.

I figure'd it would be something like this:

$("div.Test").remove();

only than with a this tag.

like image 330
Timo Vossen Avatar asked Apr 22 '26 15:04

Timo Vossen


1 Answers

Within the click event of your button:

var thisClass = $(this).attr("class");
$('div.' + thisClass).remove();
like image 132
jtrohde Avatar answered Apr 25 '26 03:04

jtrohde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!