← Back to Chapters

jQuery Hide & Show

? jQuery Hide & Show

? Quick Overview

The hide() and show() methods in jQuery allow you to easily control the visibility of HTML elements with or without animation.

? Key Concepts

  • hide() removes an element from view
  • show() brings a hidden element back
  • Optional duration creates smooth animations
  • Callbacks run after animation finishes

? Syntax & Theory

Both methods can be used with no parameters, a duration, or a duration with a callback function.

? View Code Example
// Basic hide and show syntax
$("#element").hide();
$("#element").show();

? Code Example

This box will hide and show.
? View Code Example
// Instantly hide the element
$("#hideShowBox").hide();
// Instantly show the element
$("#hideShowBox").show();

⏱️ Using Duration & Callback

You can control animation speed and execute logic after animation completes.

This box hides slowly.
? View Code Example
// Hide element with animation
$("#hideShowBox2").hide(1000);
// Show element with animation
$("#hideShowBox2").show(1000);
// Callback executes after hiding
$("#hideShowBox2").hide(1000,function(){
alert("Hidden!");
});

?️ Interactive Demo: Toggle & Speed Control

Adjust the slider to change the animation duration (ms) and use the Toggle button to switch visibility.


I am an interactive element!

? Use Cases

  • Showing and hiding menus
  • Collapsible sections
  • Improving UI interactions

✅ Tips & Best Practices

  • Use animation durations for smoother UX
  • Prefer callbacks for dependent logic
  • Avoid excessive chaining for readability

? Try It Yourself

  • Create toggle buttons with different speeds
  • Change text after hide animation
  • Experiment with fast and slow durations