9951 explained code solutions for 126 technologies


jqueryHow do I delete an element using jQuery?


To delete an element using jQuery, you can use the .remove() method. This method removes the element from the DOM and all of its child nodes. Here is an example of how to use it:

$('#some-element').remove();

This code will remove the element with the ID of some-element from the DOM.

Code explanation

  1. $('#some-element'): This is a jQuery selector which selects the element with the ID of some-element.
  2. .remove(): This is the jQuery method which removes the selected element from the DOM.

Here are some relevant links for further reading:

Edit this code on GitHub