jQuery Effects - Hide and Show


jQuery hide() and show()

With jQuery, you can hide and display HTML elements in hide() and show() modes:


Example
$("#hide").click(function(){
  $("p").hide();
});

$("#show").click(function(){
  $("p").show();
});

Syntax


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

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

Optional speed parameter specifies hide / show speed, and may take the following values: "slow", "fast", or milliseconds.

The optional dialing parameter is a function to be used after the completion of call hide() or show() (you will learn more about callback functions in the next chapter).

The following example shows a speed parameter with hide():


Example
$("button").click(function(){
  $("p").hide(1000);
});


jQuery toggle()

You can also switch between hiding and displaying something in a toggle() way.

Featured elements are hidden and hidden features are displayed:


Example
$("button").click(function(){
  $("p").toggle();
});

Syntax

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

Optional speed parameter can take the following values: "slow", "fast", or milliseconds.

Optional call parameter is a function to be used after the completion of toggle().