Is there a simpler method to display one div and hide all others, with the first one shown by default?
My current solution using jQuery works, but it feels lengthy. I believe there might be a more efficient way to achieve this.
Here is the code snippet:
$(".link-one").click(function() {
$(".div-one").show();
$(".div-two,.div-three,.div-four,.div-five").hide();
});
// Other click functions for link-two, link-three, ..., link-five
.div-two,
.div-three,
.div-four,
.div-five {
display: none
}
a {
display: inline-block;
margin-right: 10px;
padding: 5px 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#" class="link-one">Link One</a> <a href="#" class="link-two">Link Two</a> <a href="#" class="link-three">Link Three</a> <a href="#" class="link-four">Link Four</a> <a href="#" class="link-five">Link Five</a>
<div class="div-one">
Div #1
</div>
// Other divs with different content
To see a demonstration of this functionality, you can check out this JSfiddle: https://jsfiddle.net/z58ayhtw/6/