I have simple Jquery accordion, but I have problem of changing header color when tab is opened
Here is my code
HTML
<dl class="accordion-modal">
<dt><a href=""><header>FIRST</header></a></dt>
<dd class="active-accordian">FIRST CONTENT</dd>
<dt><a href=""><header>SECOND</header></a></dt>
<dd>SECOND CONTENT</dd>
</dl>
JS
(function($) {
var allPanels = $('.accordion-modal > dd').hide();
$('.accordion-modal > .active-accordian').show();
$('.accordion-modal > dt > a').click(function() {
$this = $(this);
$target = $this.parent().next();
if(!$target.hasClass('active')){
allPanels.removeClass('active').slideUp();
$target.addClass('active').slideDown();
}
return false;
});
})(jQuery);
CSS
header{
background-color:green;
}
.active{
background-color:red;
}
.active-header-color{
background-color:blue;
}
What I need when some content is show to add class to that header? Here is working fiddle https://jsfiddle.net/7hLzqoxe/4/
here is my fiddle. refer to it
All you needed to do was add display:inline-block
to <a>
element since it is inline element.
https://jsfiddle.net/7hLzqoxe/5/
This was the main part that needed a change
$('.accordion-modal > dt > a').click(function () {
$(this).children('header').addClass('green');
$(this).parent().siblings().children('a').children('header').removeClass('green'); //$(this).parent().siblings().children('a').removeClass('green');
allPanels.slideUp();
$(this).parent().next().slideDown();
return false;
});
updated JS Fiddle https://jsfiddle.net/7hLzqoxe/6/