Example 1
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of jQuery Effect Method without Callback Function</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<style>
p{
background:yellow;
font-size: 24px;
padding:20px;
}
</style>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").slideToggle("slow");
alert("The slide toggle effect has completed.");
});
});
</script>
</head>
<body>
<p>This is paragraph.</p>
<button type="button">Click me</button>
</body>
</html>
Example 2
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of jQuery Effect Method with Callback Function</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<style>
p{
background:yellow;
font-size: 24px;
padding:20px;
}
</style>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").slideToggle("slow", function(){
alert("The slide toggle effect has completed.");
});
});
});
</script>
</head>
<body>
<p>This is paragraph.</p>
<button type="button">Click me</button>
</body>
</html>
Example 3
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of jQuery Callback Executed Multiple Times</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<style>
h1{
display:none;
background:red;
padding:20px;
}
p{
background:yellow;
font-size: 24px;
padding:20px;
}
</style>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h1, p").slideToggle("slow", function(){
alert("The slide toggle effect has completed.");
});
});
});
</script>
</head>
<body>
<h1>This is heading</h1>
<p>This is paragraph.</p>
<button type="button">Click me</button>
</body>
</html>