How to destroy a DOM element with jQuery?

Suppose the jQuery object is $target.


Is $target.remove(); what you're looking for?

If you want to completely destroy the target, you have a couple of options. First you can remove the object from the DOM as described above...

console.log($target);   // jQuery object
$target.remove();       // remove target from the DOM
console.log($target);   // $target still exists

Option 1 - Then replace target with an empty jQuery object (jQuery 1.4+)

$target = $();
console.log($target);   // empty jQuery object

Option 2 - Or delete the property entirely (will cause an error if you reference it elsewhere)

delete $target;
console.log($target);   // error: $target is not defined

More reading: info about empty jQuery object, and info about delete

You are looking for the .remove() function.

Need Your Help

Could not load file or assembly 'WebMatrix.Data`

c# web-config

I updated MVC4 to MVC5. When you run the application I got an error that I don't have WebMatrix.Data. I installed it PM> Install-Package WebMatrix.Data. Now when you start getting in the browser...

How to change the UISwitch default color(blue)

ios iphone ios5 ios4

How to change the default color(blue) of a UISwitch?