I have the following problem, I made navigation arrows for some elements and depending on the active element, I need to change the CSS of another element.
In the example below I would need to change, for example, the background of the body to a specific color, every time the test2 class received the current class. I tried to do with an on change in the document but I was not successful.
var $divs = $('.box').children(".teste"),
index = 0;
$("#next").click(function() {
updateStatus(1);
});
$("#prev").click(function() {
updateStatus(-1);
});
function updateStatus(a) {
$divs.eq(index).removeClass("current").hide();
index += a;
$divs.eq(index).addClass("current").show();
$("#next").toggle((index !== $divs.length - 1));
$("#prev").toggle(index !== 0);
}
.box{
height:100px;
width:100px;
outline:1px solid red;
}
.teste{
height:50px;
width:50px;
}
.teste1{
background:#ccc;
}
.teste2{
display:none;
background:red;
}
.teste3{
display:none;
background:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="prev">Prev</div>
<div id="next">Next</div>
<div class="box">
<div class="teste teste1"></div>
<div class="teste teste2"></div>
<div class="teste teste3"></div>
</div>