jQuery show/hide Effects

With jQuery, you can use jQuery show/hide effect an HTML elements using the functions show() and hide(). The hide() can be used to hide some HTML element when some event occurs while show() can be used to display the hidden element.

Syntax of show()

The syntax contains the selector to access HTML element and a show function that contains two optional parameters. The first parameter can be used to provide the speed of the effect in milliseconds.

The second callback par
The show() reverse the effect of hide() and display the element hidden by hide(). The hide() applies the display:none CSS to the HTML element when use the jquery function while show() applies the display:block CSS.

Check the example given below to find out the changes effects.

Output

The content to display jQuery show/hide function effect.

Click the hide button given above to see the hide effect of jQuery. Now, if you want to show the hidden element, you can click the show button given above which reverses the effect of hide function.

Use the jQuery selectors to select, access the HTML element and apply the required operation.

jQuery toggle() for both jQuery show/hide effects

If you want to perform both the hide and show effects using the jQuery and don’t want to use the hide and show function. A single toggle() is an alternative you can use to perform both jQuery show/hide effect of jQuery. With only that single jQuery function you can perform both the operations.

The function is easy to use and operation is same as the jQuery show/hide function.

Output

The content to display the use of toggle function hide/show effect.

Click the toggle button given above to see the effect of the jQuery toggle(). You can notice the effect of both hide and show function with just a single toggle().

Developers use both hide() and show() while developing an application. However, if you want to show the hidden HTML element, you need to only use the show() which apply the display:block CSS to the HTML element.

The toggle() can be used only when you want to first hide the element and then show the element and vice versa.

You must also read.

Leave a Reply

Your email address will not be published. Required fields are marked *