I am looking for assistance on how to pass multiple classes within if-else statements and jQuery. My goal is to have both divs and divs2 change when the next button is clicked.
Can someone please provide guidance on achieving this?
--code not mine--
$(document).ready(function() {
$(".divs div").each(function(e) {
if (e != 0)
$(this).hide();
});
$("#next").click(function() {
if ($(".divs div:visible").next().length != 0)
$(".divs div:visible").next().show().prev().hide();
else {
$(".divs div:visible").hide();
$(".divs div:first").show();
}
return false;
});
$("#prev").click(function() {
if ($(".divs div:visible").prev().length != 0)
$(".divs div:visible").prev().show().next().hide();
else {
$(".divs div:visible").hide();
$(".divs div:last").show();
}
return false;
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="divs">
<div class="cls1">1</div>
<div class="cls2">2</div>
<div class="cls3">3</div>
</div>
<a id="prev">prev</a>
<a id="next">next</a>
<div class="divs2">
<div class="cls1">1</div>
<div class="cls2">2</div>
<div class="cls3">3</div>
</div>