The jQuery slideToggle() method toggles between the slideDown() and slideUp() methods.
Syntax
$(selector).slideToggle(speed,callback);
speed -It specifies the speed of the slideToggle effect. Default value is 400 milliseconds. Possible values:
callback - A function to be executed after the slideToggle method is completed.
The following example demonstrates the slideToggle() method.
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(){
$("#flipid").click(function(){
$("#panelid").slideToggle("slow");
});
});
</script>
<style>
#flipid {
padding: 5px;
text-align: center;
background-color: red;
border: solid 1px green;
}
#panelid {
padding: 5px;
text-align: center;
background-color: green;
border: solid 1px green;
color:white;
}
#panelid {
padding: 50px;
}
</style>
</head>
<body>
<div id="flipid">Click to slide Toggle</div>
<div id="panelid">Tutorialstrend.com!</div>
</body>
</html>
Output
Now click on the Click to slide Toggle. It will slide up as following:
Now again click on the Click to slide Toggle. It will slide down as following:
Image3