WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

jQuery - Remove Elements


With jQuery, it is anything but difficult to evacuate existing HTML elements.


Remove Elements/Content

To evacuate components and substance, there are essentially two jQuery methods:

  • remove() - Removes the chose component (and its kid elements)
  • empty() - Removes the youngster components from the chose element

jQuery expel() Method

The jQuery expel() technique evacuates the chose element(s) and its tyke elements.

Example

$("#div1").remove();

jQuery void() Method

The jQuery void() technique expels the kid components of the chose element(s).

Example

$("#div1").empty();

Filter the Elements to be Removed

The jQuery expel() strategy likewise acknowledges one parameter, which enables you to channel the components to be removed.

The parameter can be any of the jQuery selector syntaxes.

The following precedent evacuates all <p> components with class="test":  

Example

$("p").remove(".test");

This precedent evacuates all <p> components with class="test" and class="demo":  

Example

$("p").remove(".test, .demo");