jQuery hide()
0 1274
- This jquery method is used to hide the selected HTML element.
Related Topic:
jQuery Attributes
jQuery Effects
jQuery hide()
Syntax:
$(selector).hide(speed, callback);
Parameter description:
- speed: This parameter used to set the speed of hiding. It can be "slow", "fast" or any time in milliseconds. It is optional.
- callback: This represents a function that is executed after the completion of hide() method. It is also optional.
Example:
In this example, we hide the paragraph at a slow speed after a click on it.
<html>
<head>
<title>jQuery Example</title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<style>
.para{
background:lightgray;
padding:20px;
}
</style>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide("slow");
});
});
</script>
</head>
<body>
<h2>jQuery hide() method Example</h2>
<p class="para">Click me to hide</p>
<p class="para">You can click me also</p>
</body>
</html>
Output:
When you click on the paragraph it will hide at a slow speed.
Example 2:
In this example, we hide the paragraph at a fast speed after a click on it.
<html>
<head>
<title>jQuery Example</title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<style>
.para{
background:pink;
padding:20px;
}
</style>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide("fast");
});
});
</script>
</head>
<body>
<h2>jQuery hide() method Example</h2>
<p class="para">Click me to hide</p>
<p class="para">You can click me also</p>
</body>
</html>
Output:
When you click on a paragraph, it will hide at a fast speed
Example 3:
In this example, we hide the paragraph with a speed of 5 seconds after a click on it.
<html>
<head>
<title> jQuery Example </title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<style>
.para{
background:pink;
padding:20px;
}
</style>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide("5000");
});
});
</script>
</head>
<body>
<h2> jQuery hide() method Example </h2>
<p class="para"> Click me to hide </p>
<p class="para"> You can click me also </p>
</body>
</html>
When you click on a paragraph, it will hide in 5 seconds.
Share:
Comments
Waiting for your comments