I have two divs which are hidden by default. The user then reveals the div on click. If a div is already open, and the user clicks to reveal the other div, I want the current div to hide, and show the new div.
My current code is this..
HTML
<div class="menu">MENU</div>
<div class="search">SEARCH</div>
<div class="menu-box">MENU BOX</div>
<div class="search-box">SEARCH BOX</div>
CSS
.menu, .search {
display:inline-block;
cursor:pointer;
}
.menu, .search, .menu-box, .search-box {
padding:20px;
background-color: #ccc;
margin-right:10px;
}
.menu-box, .search-box {
width:20%;
display:none;
}
.menu-box {
background-color:red;
}
.search-box {
background-color:green;
}
JAVASCRIPT
$('.menu').click(function(){
$('.menu-box').slideToggle();
});
$('.search').click(function(){
$('.search-box').slideToggle();
});
You can see a working demo here...
http://codepen.io/seraphzz/pen/zbHDk
I have had a look around for help, but all the solutions are found are for tabs, where one div is always showing. This is not what I am after. A div should only be showing if that link was clicked on.
So to confirm, if the 'menu' div is already open, and the user clicks on 'search', I want the 'menu' div to hide and the 'search' to show. The two divs should never be showing at the same time!
Thanks in advance