agyanadda@gmail.com

jQuery Hide and Show

jQuery Effects 1 min read Updated Dec 1, 2026 Topic 6 of 25

The three methods

  • .hide() — hide elements
  • .show() — show hidden elements
  • .toggle() — hide if visible, show if hidden

Speed

Add a speed to animate: 'slow', 'fast' or milliseconds:

$('#info').hide(600);

Callback

A function that runs after the effect finishes:

$('#info').hide('slow', function () {
  alert('Hidden!');
});

Check visibility

$('#info').is(':visible') returns true or false.

These methods change display, so hidden elements take no space.

Example

Example — Read more / read less HTML
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

<p>jQuery makes simple effects very easy.
  <span id="more" style="display:none">With one line you can hide, show or toggle any element, add speed and even run code after the effect ends.</span>
</p>
<button id="toggle">Read more</button>

<script>
  $(function () {
    $('#toggle').click(function () {
      const $btn = $(this);
      $('#more').toggle('fast', function () {
        $btn.text($('#more').is(':visible') ? 'Read less' : 'Read more');
      });
    });
  });
</script>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which method switches between hidden and visible?

Exercise 2 True / False

A callback runs after the effect has finished.

Exercise 3 Fill in the Blank

$('#box').is(':___') checks if the box is shown.

Frequently Asked Questions

Add style="display:none" in the HTML (or a CSS class), then use .show() or .toggle() to reveal it.