jQuery Toggle Show Hide Effects

jQuery Toggle Show Hide Effects

jQuery show hide toggle method; Through this tutorial, you will learn how to use jQuery show hide toggle method for hide, show, and toggle HTML (div, p, h1…h6, span tag) elements on click.

If you are working with HTML elements and you have to toggle your HTML elements like div, p tag, h1..h6 tag, span tag, button tag, etc. on click and Hide or Show or toggle. Then this tutorial is for you.

jQuery Toggle Show Hide Effects

You can show hide toggle HTML elements like div, p, button tag using the jQuery show(), hide() and toggle() effect methods:

  • jQuery Show() Method Effect
  • jQuery Hide() Method Effect
  • jQuery toggle() Method Effect

jQuery Show() Method Effect

The jQuery show() effect method is used to show the selected Html elements.

Syntax

 $(selector).show();  
$(selector).show(speed, callback);
$(selector).show(speed, easing, callback);

Parameters of Show Method

  • speed:- The argument ‘speed‘ determines the duration of this effect.
  • easing:- It specifies the easing function to be used for transition.
  • callback:- This is an optional parameter. you can specify what to do after the hide() method is called.

jQuery show() example

In the below example you can see that show() effect method.

<!DOCTYPE html>
<html>
<head>
<title> jQuery Show </title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>   
<script>
$(document).ready(function(){
$(".btn-show").click(function(){
  $("#first").show();
  });
});
</script>
</head>
<body>

<h4 id="first" style="display: none"> Hide and Show - Speed</h4>
<button class="btn-show">Show</button>

</body>
</html>

jQuery show and callback example

<!DOCTYPE html>
<html>
<head>
<title> jQuery Show with callback</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>   
<script>
$(document).ready(function(){
$(".btn-show").click(function(){
    $("#first").show(1000,"swing",function(){
      alert("Show() method is finished!");
    });
  });
});
</script>
</head>
<body>

<h4 id="first" style="display: none"> Hide and Show - Speed</h4>
<button class="btn-show">Show</button>

</body>
</html>

jQuery Hide() Method Effect

The jQuery hide() effect method is used to hide the selected Html elements.

Syntax

 $(selector).hide();  
$(selector).hide(speed, callback);
$(selector).hide(speed, easing, callback);

Parameters of Hide() Method

  • speed:- The argument ‘speed‘ determines the duration of this effect.
  • easing:- It specifies the easing function to be used for transition.
  • callback:- This is an optional parameter. you can specify what to do after the hide() method is called.

jQuery Hide() example

<!DOCTYPE html>
<html>
<head>
<title> jQuery Hide Method </title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>   
<script>
$(document).ready(function(){
  $(".btn-hide").click(function(){
  $("#first_hide").hide("fast");
  });

$(".btn-show").click(function(){
  $("#first_hide").show("fast");
  });
});
</script>
</head>
<body>

<h4 id="first_hide"> Hide and Show - Speed</h4>
<button class="btn-hide">Hide</button>
<button class="btn-show">Show</button>

</body>
</html>

jQuery hide and callback example

<!DOCTYPE html>
<html>
<head>
<title> jQuery Show & Hide with callback</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>   
<script>
$(document).ready(function(){
  $(".btn-hide").click(function(){
    $("#second").hide(1000,"swing",function(){
      alert("Hide() method is finished!");
    });
  });
$(".btn-show").click(function(){
    $("#second").show(1000,"swing",function(){
      alert("Show() method is finished!");
    });
  });
});
</script>
</head>
<body>

<h4 id="second"> Hide and Show - Speed</h4>
<button class="btn-hide">Hide</button>
<button class="btn-show">Show</button>

</body>
</html>

jQuery toggle() Method Effect

toggle() method is used to change the to show or hide HTML elements (like input, text, paragraph, div, image, etc.). You can use the toggle method when you want to toggle between the hide and show of the selected HTML element.

Syntax

 $(selector).toggle();  
 $(selector).toggle(speed, callback);  
 $(selector).toggle(speed, easing, callback);

Parameters of Toggle() Method

  • speed:- The argument ‘speed‘ determines the duration of this effect.
  • easing:- It specifies the easing function to be used for transition.
  • callback:- This is an optional parameter. you can specify what to do after the hide() method is called.

jQuery toggle() example

In the below example you can see that the toggle() method takes an argument “fast” to toggle between hide and show the selected <p> tag element.

<!DOCTYPE html>
<html>
<head>
<title> jQuery Toggle </title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<script>
$(document).ready(function(){
  $(".togglebtn").click(function(){
  $("#second").toggle("fast");
  });

});
</script>
</head>
<body>

<h4 id="second"> Hide and Show - Speed</h4>
<button class="togglebtn">Toggle</button>

</body>
</html>

You may like

  1. jQuery Text Method By Example
  2. Get and Set Input, Select box, Text, radio Value jQuery
  3. Duplicate Html Elements Using jQuery By Example
  4. jQuery | Event MouseUp By Example
  5. Event jQuery Mouseleave By Example
  6. jQuery Event Mouseenter Example
  7. Event jQuery MouseOver & MouseOut By Example
  8. keyup jquery event example
  9. Jquery Click Event Method with E.g.
  10. Event jQuery. Blur By Example
  11. jQuery form submit event with example
  12. keydown function jQuery
  13. List of jQuery Events Handling Methods with examples
  14. Jquery Selector by .class | name | #id | Elements
  15. How to Get the Current Page URL in jQuery

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *