I've been experimenting with switching between two divs using two buttons, but I can't seem to get it right. I've searched all over the internet, but nothing has worked for me so far. Can you please point out what I might be doing wrong? Also, is there a way to achieve this without using jQuery?
Below is the code snippet I am currently working with:
// Show only one panel at a time
jQuery(".flip").on("click", function(e) {
var target = jQuery(this).attr("href");
jQuery(target).slideToggle("fast");
jQuery(".content").not(target).hide();
e.preventDefault();
});
.button-wrapper {
text-align: center;
}
.button-wrapper a {
text-decoration: none;
color: black;
margin: 10px
}
.content h1 {
text-align: center;
margin-top: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="button-wrapper">
<a class="flip top-button" href="#first-div" target="" data-toggle="">Div1</a>
<a class="flip top-button" href="#second-div" target="" data-toggle="">Div2</a>
</div>
<div class="content" id="cont1">
<h1>I'm the first DIV</h1>
</div>
<div class="content" id="cont2">
<h1>I'm the second DIV</h1>
</div>
If you'd like to see this in action, check out my Codepen page here: