I have following code for toggle slide in jquery.
But this is working only on one div. How can I use it in loop for mutiple div’s like for e.g. flip1/panel1, flip2/panel2 etc.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
<style>
#panel,#flip
{
padding:5px;
text-align:center;
background-color:#e5eecc;
border:solid 1px #c3c3c3;
}
#panel
{
padding:50px;
display:none;
}
</style>
</head>
<body>
<div id="flip">Click to slide the panel down or up</div>
<div id="panel">Hello world!</div>
</body>
</html>
Use classes, ids should be unique to a page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sliding panels</title>
<style>
.panel,.flip{
padding:5px;
text-align:center;
background-color:#e5eecc;
border:solid 1px #c3c3c3;
}
.panel{
padding:50px;
display:none;
}
</style>
</head>
<body>
<div class="flip">Click to slide the panel down or up</div>
<div class="panel">Hello world!</div>
<div class="flip">Click to slide the panel down or up</div>
<div class="panel">Hello world!</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(".flip").on("click", function(){
$(this).next(".panel").slideToggle("slow");
});
</script>
</body>
</html>
1 Like
Thank you so much for the kind solution.
Thanks & regards
No problem.
Don’t forget, you can use the like button (the heart underneath a post) to indicate posts you like or have found helpful.
1 Like
system
Closed
5
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.