Alex Rivera | Logout

Loading all objects with class into an array using jQuery

Asked 2009-02-16T19:46:52.153
10

I have a bunch of div's on my page with class testClass.

I want to load them into an array and then check the array's size.

But its not working?

myArray = $('testClass');

alert(myArray.count);

What's wrong?

Edit
Report

1 Answer

18

You have:

myArray = $('testClass');
alert(myArray.count);

You want:

myArray = $('.testClass');
alert(myArray.length);

Notice, first, the . for testClass. Then, myArray is a JavaScript object, so you have access to the length key.

answered 2009-02-16T20:00:51.013

Your Answer