jQuery hide()

Introduction

Hide all <p> elements:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*w  w  w.  j av  a2s  . c om*/
<script>
$(document).ready(function(){
  $(".btn1").click(function(){
    $("p").hide();
  });
  $(".btn2").click(function(){
    $("p").show();
  });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>

<button class="btn1">Hide</button>
<button class="btn2">Show</button>

</body>
</html>

The hide() method hides the selected elements.

This method is similar to the CSS property display:none.

Hidden elements will not be displayed at all.

They no longer affect the layout of the page.

To show hidden elements, look at the show() method.

$(selector).hide(speed,easing,callback)
Parameter
Optional
Description
speed





Optional.





speed of the hide effect.
Default value is 400 milliseconds
Possible values:
milliseconds
"slow"
"fast"
easing




Optional.




speed of the element in different points of the animation.
Default value is "swing"
Possible values:
"swing" - moves slower at the beginning/end, faster in the middle
"linear" - moves in a constant speed
callback
Optional.
A function to be executed after the hide() method is completed



PreviousNext

Related