The fix is ββsimple:
$("#topbar").toggle(function () { $(this).animate({ height: "40px" }, 200); }, function () { $(this).animate({ height: "10px" }, 200); });
You just need to add px units to the height value.
See demo at: http://jsfiddle.net/audetwebdesign/3dd3s/
PS
Some of the other posted answers show the best way to code this type of animation. I just demonstrated how to fix the error.
Note that this use of .toggle is deprecated since jQuery 1.8.
Link: http://api.jquery.com/toggle-event/
Why do I need a block
Some of the other solutions include the jQuery .height() function, which returns a pixel value without a unit. In this case, the computed value is forcibly / excellent is the pixel value, so the unit "px" is not required.
In the original example, the .height() function was not used, so you had to specify the units for them to work.
source share