jQuery Effect - fadeTo() Method

Example

Use the fade out effect to hide a <p> element:

$(".btn1").click(function(){
  $("p").fadeTo(1000,0.4);
});

Try It Yourself

Definition and Usage

The fadeTo() method gradually changes the opacity of the selected elements to the specified value.

Syntax

$(selector).fadeTo(speed,opacity,callback)
Parameters Description
speed

Optional. Specifies the speed at which the element's opacity changes from the current opacity to the specified opacity.

Possible values:

  • Milliseconds (e.g., 1500)
  • "slow"
  • "normal"
  • "fast"
opacity Required. Specifies the opacity to fade in or out. It must be a number between 0.00 and 1.00.
callback

Optional. The function to be executed after the fadeTo function is executed.

For more information about callback, please visit our jQuery Callback chapter.

The speed parameter cannot be set unless it is set.