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

Converting DOM Objects into jQuery Objects

var containerObj = document.getElementById("myDiv"); $(containerObj); //Equivalent to $("#myDiv"); var objs = document.getElementsByClassName("myClass"); $(objs); //Equivalent to $(".myClass "); var objs = document.getElementsByTagName("div"); $(objs); //Equivalent to $("div");

The jQuery constructor $() accepts DOM objects and arrays as an argument. If you pass in a DOM object, $() converts the DOM object or array into a jQuery object that you can then manipulate in the normal jQuery way.

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