3

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!

Flo
  • 1,179
  • 3
  • 15
  • 43

1 Answers1

1

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

haim770
  • 48,394
  • 7
  • 105
  • 133
  • Oh okay! But i would only display one Element of the classes... how can i do this? – Flo Nov 11 '14 at 07:34
  • Okay, and the second element of class? – Flo Nov 11 '14 at 07:38
  • I am also getting the same error when I use toggle like this var anim = "slide"; var duration = 500; var options = { direction: 'left' }; $("#cbp-spmenu-s1").toggle(anim, options, duration); – PSR Dec 15 '14 at 12:11