hide() in jQuery
To hide elements in jQuery, hide() method is used.
This method is similar to the CSS property (display:"none"). But in here the value of the display property is saved in jQuery's data cache. By doing so the hidden value can be restored to its initial value
.hide() can be used as an animation method by providing a duration, a plain object, or a "complete" function.
When the .hide() is used as the animation method, the width, height, and opacity of the elements are animated simultaneously.
Durations are specified in milliseconds, higher values are used to indicate slower animations.
By setting jQuery.fx.off = true all jQuery effects can be turned off globally , which in turn sets the duration to 0.
The above syntax is used to hide the elements immediately without any animation.
- duration - It is optional and is used to specify the delay. It can have three values
- Default value is 400.
- number - Integer values are given in milliseconds.
- slow - It denotes 600 milliseconds.
- fast - It denotes 200 milliseconds.
- easing - It is optional and is used to specify the speed at which the animation progresses.It can have two values.
- swing - It is a default value, animation progresses in an irregular way.
- linear - It specifies that the animation progresses at a constant pace.
- complete - It is optional. It indicates a function which will be executed after the element is hidden.
- options - Given below options are optional
- duration - It can be defined by string or number and is used to determine how long the animation will run.
- easing - It is defined by string and is used to determine for transition which easing function to be used.
- queue - It is denoted by Boolean, and is used to determine whether to place the animation in the effects queue. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it. If it is specified as false, the animation will begin immediately.
- specialEasing - It is an object which contains one or more of the CSS properties and these properties are defined by arguments and its corresponding easing functions.
- step - It is used to denote a function for each element when calling animated property.
- progress - It is used to denote a function to be called after each step of the animation.
- complete - It is used to denote a function, which is called after the animation on an element is complete.
- start - It is used to denote a function, when the elements animation begins.
- done - It is used to denote a function, when the animation on an element completes.
- fail - It is used to denote a function, when the animation of an element fails to complete.
- always - It is used to denote a function, when the animation on an element completes or stops without completing.
Example 1 - hiding without animation
Example 2 - hiding element within specified milliseconds
Example 3 - hide() with complete function
Example 4 - calling complete function using function name
Example 5 - Hiding element using easing(linear) value
We are recommended to start the semi colon at starting
Example 6 - hide() with options
Example 7 - hide() with options and progress bar