jQuery fadeTo() Method (original) (raw)
Last Updated : 11 Jul, 2025
The fadeTo() method is an inbuilt method in jQuery that is used to change the opacity of the selected element.
Syntax:
$(selector).fadeTo(speed, opacity, easing, call_function)
Here selector is the selected element.
Parameter: It accepts four parameters which are specified below-
- speed: It specifies the speed of the fading effect.
- opacity: It specifies to fade and this value should be between 0.0 and 1.0.
- easing: It specifies the speed at different points of animation.
- call_function: It is an optional parameter and performs a function after performing fadeTo method.
Return Value: It does not return any value.
Example 1: In the below code, no optional function parameter is passed.
HTML `
This paragraph will fade out !
<!-- After clicking on this paragraph this
paragraph will not fade out -->
<p>
This paragraph will not fade !
</p>
<!-- jQuery code to show working
of this method -->
<script>
$("p:first").click(function () {
$(this).fadeTo("slow", 0.33);
});
</script>
`
Output:
Example 2: In the below code, an optional function parameter is passed.
HTML `
<!-- jQuery code to show the working of this method -->
<script>
$(document).ready(function () {
$("button").click(function () {
$("p").fadeTo(2000, 0.2, function () {
alert("The fadeTo effect has finished!");
});
});
});
</script>
<style>
body {
width: 40%;
height: 100px;
border: 2px solid green;
padding: 20px;
}
</style>
<!-- This paragraph will fade out -->
<p>This is a paragraph.</p>
<!-- Click on this button and
paragraph will fade out -->
<button>Click me</button>
`
Output:

