I have interesting problem with toggleClass();
I got 5 input image elements and I want to do switch image (input src) using toggleClass but I don't understand why toggleClass is not doing that I want to do ?
$(".form-elements input[type='button']").on("click", function() {
var el = $(this).attr("class");
if(el=="d1"){
$(".d1").toggleClass('d1 d1_pasif');
}else if(el=="d2"){
$(".d2").toggleClass('d2 d2_pasif');
}else if(el=="d3"){
$(".d3").toggleClass('d3 d3_pasif');
}else if(el=="d4"){
$(".d4").toggleClass('d4 d4_pasif');
} else if(el=="d5"){
$(".d5").toggleClass('d5 d5_pasif');
}
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="form-elements">
<input type="image" name="d5" class="d5" src="http://anitur.streamprovider.net/images/otel-filtre/d5.png" />
<input type="image" name="d4" class="d4" src="http://anitur.streamprovider.net/images/otel-filtre/d4.png" />
<input type="image" name="d3" class="d3" src="http://anitur.streamprovider.net/images/otel-filtre/d3.png" />
<input type="image" name="d2" class="d2" src="http://anitur.streamprovider.net/images/otel-filtre/d2.png" />
<input type="image" name="d1" class="d1" src="http://anitur.streamprovider.net/images/otel-filtre/d1.png" />
</div>
I have a and b images, When I click a image it has to be b images and when I click b images it has to be a images.
thanks.