Emad Helmi
Emad Helmi

Reputation: 43

working with objects in an array in javascript and jquery

i have chosen some of div elements in HTML and save them in an array

var Div = $(".etc") ;

i want to use this notation to slide-toggle Div elements with this code ;

Div[0].slideToggle(...) ;

but it doesn't work and doesn't toggle the element . although i try to alert element's value or name and other attributes but it doesn't work.

Upvotes: 0

Views: 52

Answers (3)

A. Wolff
A. Wolff

Reputation: 74420

Use eq():

Div.eq(0).slideToggle(...);

Upvotes: 3

Jon
Jon

Reputation: 437336

The bracket notation returns DOM elements, which do not have a slideToggle method. What you want is .eq, which filters in the same manner but returns jQuery objects instead:

Div.eq(0).slideToggle(...) ;

Upvotes: 4

user405398
user405398

Reputation:

Try:

$(Div[0]).slideToggle(...) ;

Or:

Div.eq(0).slideToggle(...) ;

.eq()

Upvotes: 2

Related Questions