Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery toggle - Uncaught TypeError: undefined is not a function

i try to show one element of a class with this jquery code:

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

but i get this error:

Uncaught TypeError: undefined is not a function 

and code lick this works fine:

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

also if i try to get the element in console so it works

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

Can you help me? Thank you!

like image 653
Flo Avatar asked Sep 04 '26 15:09

Flo


1 Answers

When you're using get(), jQuery returns the native (underlying) DOM object from the array of elements in context and that HTMLElement doesn't provide the toggle() method.

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

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

See Documentation

like image 156
haim770 Avatar answered Sep 06 '26 05:09

haim770



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!