I have the following problem on hand: Create two buttons that will show/hide corresponding content underneath. I achieved it using this code:
$(document).ready(function() {
$("#button2").click(function() {
$(".content1").hide();
$(".content2").show();
});
$("#button1").click(function() {
$(".content1").show();
$(".content2").hide();
});
});
.content1 {
display: none;
}
.frequency {
display: flex;
}
.frequency button {
border: 2px solid red;
padding: 25px 20px;
}
.frequency>button:hover,
.frequency>button.active {
background-color: red;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="frequency">
<button id="button1">button1text</button>
<button id="button2">button2text</button>
</div>
<div class="content1">text1</div>
<div class="content2">text2</div>
To take this one step further, I would like the last button that was clicked to stay highlighted (red). I tried playing with addClass, but the code got very messy.
Any suggestions?