Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
hide()
and show()
MethodsThese methods allow you to toggle visibility of elements on your webpage.
$(selector).hide(); // Hides the selected element(s) $(selector).show(); // Shows the selected element(s)
Try it yourself
You can also add speed to make the hiding or showing smoother:
$(selector).hide(speed, callback); $(selector).show(speed, callback);
speed
– Optional. Defines the speed of the animation: Can be "slow"
, "fast"
, or a time in milliseconds (e.g., 1000
)callback
– Optional. A function to execute after the animation completes.Try it yourself
The toggle()
method is used to switch between hiding and showing an element.
It's a shortcut that replaces writing both hide()
and show()
manually.
toggle()
will hide it.toggle()
will show it.Try it yourself