I've got this basic accordion which toggles a class of 'block'. Everything is working, except
the .not(this)
in $('.accordionInner').not(this).removeClass('block');
is not working, so you can never close all the accordions. I am sure it is a simple fix, but I don't know what I'm doing wrong.
HTML:
<div class="accordionHeading">
<p>Header</p>
</div>
<div class="accordionInner">
<p>Inner</p>
</div>
<div class="accordionHeading">
<p>Header</p>
</div>
<div class="accordionInner">
<p>Inner</p>
</div>
CSS:
.accordionHeading {
cursor: pointer;
background: yellow;
}
.accordionInner {
display: none;
}
.block {
display: block !important;
}
JS:
$('body').on('click', '.accordionHeading', function(){
$('.accordionInner').not(this).removeClass('block');
$(this).next('.accordionInner').toggleClass('block');
});