HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Hide, Show, Toggle, Slide, Fade, and Animate. WOW!
With jQuery, you can hide and show HTML elements with the hide()
and show()
methods:
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
The optional speed parameter specifies the speed of the hiding/showing, and can take the following values: "slow", "fast", or milliseconds.
The optional callback parameter is a function to be executed after
the hide()
or show()
method completes (you will learn more about callback functions in a
later chapter).
The following example demonstrates the speed parameter with hide()
:
$("button").click(function(){
$("p").hide(1000);
});
You can also toggle between hiding and showing an element with the toggle()
method.
Shown elements are hidden and hidden elements are shown:
$("button").click(function(){
$("p").toggle();
});
The optional speed parameter can take the following values: "slow", "fast", or milliseconds.
The optional callback parameter is a function to be executed after
toggle()
completes.
Use a jQuery method to hide a <p> element when it is clicked on.
$("p").click(function(){ $(this).(); });
For a complete overview of all jQuery effects, please go to our jQuery Effect Reference.