Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Spoiler Revealer Perform: Part 1

Miguel Nunez
Miguel Nunez
3,266 Points

What is a jQuery object?

I know what a java script object is and I know how to create arrays and objects in JavaScript but in jQuery can any one give me an example of a jQuery object in action and tell me what sections or components that are consider a jQuery object visually and how do I access them like how I did in JavaScript.

1 Answer

When the jQuery function is invoked with a CSS selector, it will return a jQuery Object wrapping all the elements that match the selector. The jQuery object has properties like length and methods on it like ready(), click() etc. The jQuery object just wraps the DOM elements to make interactivity and DOM manipulation easier.

One important thing. jQuery Objects behaves both like an objects and an arrays. You treat it like an object when you chain, but you can also treat it like array. For example -

// This div contains several elements.
var divs =  $("div");
for (i=0; i<divs.length; i++){
  console.log(divs[i]);
}