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

Adding DOM Elements to the jQuery Object Set

var pars = $("p");   //contains all <p> elements var pAndDiv = $("div").add(pars);   //contains all <div> and <p> elements var pAndDivAndSpan = $("span").add("p").add("div");   //contains all <span> and <div> and <p> elements

A great feature of jQuery is how easy it is to add additional elements to the jQuery object set. The .add(selector) method adds elements that match the selector to the set represented by the jQuery object.

The .add(object) method accepts another jQuery object and adds the elements in that object to the current object’s set.

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