I am trying to make a show hide div function for my website. But I have one problem with multiple show hide button. So the problem is that when I click show button in container div then all blue div showing automatically.
You can see a DEMO.
HTML:
<div class="container"> <div class="div"> <div id="hidediv">Hide</div> </div> <div class="test"></div> <div id="showdiv">Show</div> </div> <div class="container"> <div class="div"> <div id="hidediv">Hide</div> </div> <div class="test"></div> <div id="showdiv">Show</div> </div> JavaScript:
$(document).ready(function() { $("#hidediv").hide(); $('#showdiv').click(function() { $('.div').toggle("slide"); $("#showdiv").hide(); $("#hidediv").show(); }); $('#hidediv').click(function() { $('.div').toggle("slide"); $("#hidediv").hide(); $("#showdiv").show(); }); }); When the user clicks show button in container show div, then I only want to show this div. I hope you can understand me.
.siblingsand similar jQ methonds to reach certain elements.