O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing Elements from the Page

$("p").remove(); $("p").remove(".menu"); $("#myList").children("li").remove();

You remove elements from the web page using the .remove([selector]) method on the jQuery object. This method modifies the DOM and removes the nodes from the tree.

There are a few different ways to use the .remove() method. Calling .remove() with no parameters removes all elements in the jQuery object’s set. For example, the following statement removes all <p> elements:

$("p").remove();

You can also pass a selector into .remove(), which limits the removal to items in the set that match the selector value. For example, the following statement removes all <p> elements with class="menu":

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required