Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Karan Nahar
Karan Nahar
16,147 Points

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]);
}