The jQuery fadeTo() method allows fading to a given opacity (value between 0 and 1).
Syntax
$(selector).fadeTo(speed,opacity,callback);
speed -It specifies the speed of the fadeTo effect. Default value is 400 milliseconds. Possible values:
callback - A function to be executed after the fading method is completed.
The following example demonstrates the fadeTo() method with different parameters.
Example
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#box1").fadeTo("slow", 0.12);
$("#box2").fadeTo("slow", 0.2);
$("#box3").fadeTo("slow", 0.07);
});
});
</script>
</head>
<body>
<button>Click to fade To boxes button</button><br><br>
<div id="box1" style="width:80px;height:80px;background-color:red;"></div><br>
<div id="box2" style="width:80px;height:80px;background-color:green;"></div><br>
<div id="box3" style="width:80px;height:80px;background-color:blue;"></div>
</body>
</html>
Output
Now click on button you will see the box opacity.