Removing Objects from the jQuery Object Set

var items = $("span"); items.css({color:"red"});   //colors text in all <span> elements red items.remove(".menu"): items.css({"font_weight":"bold"});   //set all <span> elements except .menu to bold

Another great feature of jQuery is how easy it is to remove items from and add additional elements to the jQuery object set. The .remove([selector]) method will remove elements  that match the selector from the set represented by the jQuery object. Calling .remove() with no selector will remove all elements from the set.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.