JQuery toggle - Uncaught TypeError: undefined is not a function

I am trying to show one class element with this jquery code:

jQuery('.slide_cover').get(0).toggle(800);

      

but I am getting this error:

Uncaught TypeError: undefined is not a function 

      

and the code licks this works great:

jQuery('.slide_cover').toggle(800);

      

also if i try to get the item in the console to make it work

jQuery('.slide_cover').get(0)

      

Could you help me? Thank!

+3


source to share


1 answer


When you use get()

, jQuery returns its own (main) DOM object from an array of elements in the context and that HTMLElement

doesn't provide a method toggle()

.

If you toggle

only want to call on the first element in the context, try this:



jQuery('.slide_cover:first').toggle(800);

      

See Documentation

+1


source







All Articles