The jQuery Show method is used to un-hide (show) hidden elements in a web page. This is similar to the CSS property display:block.
Note: jQuery Show method works on element that are display:none but not on visibility:hidden.
$(selector).show(speed,easing,callback)
Note that all the 3 parameters of show method are optional.
Parameter | Description |
---|---|
speed | Specifies the speed of the show effect. It can have values: “slow”, “fast”, In milliseconds eg “200”, “300”, “1000”, etc. |
easing | Easing creates animated effect while showing an element. It defines the speed of the element in different points of the animation. The default value is “swing”. Easing values can be: “swing” – slower at the beginning & end. Faster in the middle, “linear” – constant speed. |
callback | A function that executes after the .show() method completes. |
The below div is hidden because of style=”display:none”.
<div id="div1" style="display:none">
Hello, How are you ?
</div>
To show the div, the jQuery code will be:
$("#div1").show();
This time the hidden div will be shown by passing the callback function to the .show() method.
This function will be called when the .show() process is completed.
<div id="div2" style="display:none">
Hello, How are you ?
</div>
So, when the show process gets completed then an alert box is shown.
$("#div2").show(function () {
alert("Show method is completed!");
});
Now in this example I will use all the 3 parameters of the jQuery show method.
<div id="div3" style="display:none">
Hello, How are you ?
</div>
The below .show() code will do the showing process in slow & linear manner, then a callback function will be called after the show process is completed.
$("#div3").show("slow", "linear", function () {
alert("Show method is completed!");
});
The link to download the source code is below: