Click here for the picture I have a list of items: a, b, c, d, e, f. Whenever I click on item b, it becomes active and the other elements lose the "active" class. When an element has the "active" class, I want the background to change accordingly. If it doesn't have the class, I want to display a different image.
/* when clicking on item b */
$("#item-b").click(function() {
$("#content-a, #content-c, #content-d, #content-e, #content-f").hide();
$("#content-b").removeClass("hidden");
$("#content-b").show();
$("#item-b").addClass("active");
event.preventDefault();
});
if ($("#item-b").hasClass("active")) {
$('#img-b').attr('src', 'img/img-b-active.png'); /* change image icon */
$('.section-grey').css("background-image", "url(img/bg-ateliers-cuisine.png)"); /* change background */
$('#btn-offre').css("background-color", "#ffbf4a"); /* change button color */
} else {
alert("No active class found"); /* Display another image here */
}