I’m having a little problem implementing some jQuery into a page I am doing.
I’ve got about half way to making it do what I want, but I can’t get my head around the last part. Though I’ve used snippets of jQuery for a while I’m pretty new when it comes to writing my own code.
Basically I want 4 Divs which are hidden by default to be opened by clicking on the relevant link, but only one Div should be shown at any one time, so if Div1 has been opened, clicking the Div2 button closes Div1 and opens Div2.
Also there is a 5th button, which opens Div1 is no Divs are open, or if any Div is open, to close that open Div.
I’ve been looking at these pages for help, but nothing is exactly what I’m after:
http://css-tricks.com/forums/discussion/16451/.slidetoggle-one-div-a-time-problems-please-help/p1
http://www.randomsnippets.com/2011/04/10/how-to-hide-show-or-toggle-your-div-with-jquery/
webdesignerwall.com/tutorials/jquery-tutorials-for-designers
At the moment I’ve made it so that the Divs appear on a button click, but that’s all, I can’t work out to make the toggle logic from these examples work on my code.
I’ve set up a JSFiddle here:
http://jsfiddle.net/vx6qu/2/
Thanks in advance
You were close, but there is a cleaner approach:
http://jsfiddle.net/jbabey/vx6qu/3/