I haven't seen many accordions linked to an image next to it opposed to an image in the body so decided to play around with it a bit. I can't seem to get the css to be applied to the active class though even though the class itself changes. Does the h3 need to be a button for that to work? I just want the active class to have a - instead of a + and to have a darker colour applied. Any tips would be appreciated. I think the JQuery is right, it might just be my css or something. Here is the code so far -
// Hide all panels
let panels = $("#services__accordion > .accordion > .accordion__body").hide()
// Hide all accordion images
images = $("#accordion__img > img").hide();
// Show first panel at start
panels.first().show();
// Show first accordion image at start
images.first().show();
// On click of a panel title
$("#services__accordion .accordion h3").click(function() {
// The panel is not the H3, but its parent.
let panel = $(this).parent(),
tabName = panel.attr("tab-name"),
image = $("#" + tabName + "-img");
//Slide Up all other panels
panels.slideUp();
images.slideUp();
// Slide Down target panel, and target image.
panel.find(".accordion__body").slideDown();
image.slideDown();
return false;
});
});
//Add active class
$(".accordion h3").on('click', function(){
$(".accordion h3").removeClass('active');
$(this).addClass('active');
});
and the jsfiddle here - https://jsfiddle.net/MarioL/32nv0szw/ Thanks!