I have a set of 5 image buttons, each meant to trigger different content within a div. When the page loads, there should be default content displayed in the div that gets replaced by the content of the button clicked. The previously displayed content should be replaced when another button is clicked.
This is my current setup:
HTML:
$('.section-link').click(function() {
var cur = $('.section-link').index($(this));
$('.section-display').removeClass('active');
$('.section-display').eq(cur).addClass('active');
});
.section-display:not(.active) {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<a href="#"><img class="button1 section-link" src="button1.jpg" alt=""></a>
<a href="#"><img class="button2 section-link" src="button2.jpg" alt=""></a>
<a href="#"><img class="button3 section-link" src="button3.jpg" alt=""></a>
<a href="#"><img class="button4 section-link" src="button4.jpg" alt=""></a>
<a href="#"><img class="button5 section-link" src="button5.jpg" alt=""></a>
// Default CONTENT when page loaded
<div class="section-display active">
<h2 class="title">Default Ipsum</h2>
<h2 class="text">"Lorem ipsum dolor sit amet, consectetur adipiscing elit."</h2>
</div>
<div class="section-display">
<h2 class="title">First Ipsum</h2>
<h2 class="text">"Lorem ipsum dolor sit amet, consectetur adipiscing elit."</h2>
</div>
<div class="section-display">
<h2 class="title">Second Ipsum</h2>
<h2 class="text">"Lorem ipsum dolor sit amet, consectetur adipiscing elit."</h2>
</div>
<div class="section-display">
<h2 class="title">Third Ipsum</h2>
<h2 class="text">"Lorem ipsum dolor sit amet, consectetur adipiscing elit."</h2>
</div>
<div class="section-display">
<h2 class="title">Fourth Ipsum</h2>
<h2 class="text">"Lorem ipsum dolor sit amet, consectetur adipiscing elit."</h2>
</div>
<div class="section-display">
<h2 class="title">Fifth Ipsum</h2>
<h2 class="text">"Lorem ipsum dolor sit amet, consectetur adipiscing elit."</h2>
</div>