How to make a DIV from a JQuery Slidedown close onclick of a different one?
Question
I am doing a Jquery SlideDown on Multiple Dvi ID and this is the code that I have. It works really well however, I would like to see if it is possible to make the opened div close as you open another one. Note: I will be using more then two divs.
<script type="text/javascript">
$(document).ready(function () {
$('a.slidecontrol').click(function(){
var $this = $(this);
var divID = $this.attr("id").replace("slidecontrol_", "slidedisplay_");
var $div = $('#'+divID);
if ($div.is(':visible')) {
$div.slideUp(500);
} else {
$div.slideDown(500);
}
return false;
});
});
</script>
</head>
<body>
<a href="#" id="slidecontrol_1" class="slidecontrol">Read More</a>
<div id="slidedisplay_1" style="display:none;">Display #1</div>
<hr/>
<a href="#" id="slidecontrol_2" class="slidecontrol">Read More 2</a>
<div id="slidedisplay_2" style="display:none;">Display #2</div>
</body>
</html>
Thanks! Sophie
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow