var headers = document.querySelectorAll('.tabSectionHeader'); headers.forEach(function (header) { header.addEventListener('click', function () { var clickedParent = header.parentNode; headers.forEach(function (otherHeader) { var otherParent = otherHeader.parentNode; if (otherParent !== clickedParent) { otherParent.classList.remove('chartActiveOpenClose'); } }); clickedParent.classList.toggle('chartActiveOpenClose'); }); });