function tabSelection(evt) { const self = evt.target; for (const ts of self.parentElement.parentElement.children) { ts.classList.remove('is-active'); } self.parentNode.classList.add('is-active'); const bodies = self.parentElement.parentElement.parentElement.parentElement.children[1].children; for (const ts of bodies) { ts.classList.add('is-hidden'); } bodies[+self.parentElement.attributes.data.value].classList.remove('is-hidden'); } document.addEventListener("DOMContentLoaded", function() { const tabSections = document.getElementsByClassName("jwm-mail-body-multipart-alternative"); for (const ts of tabSections) { Array.from(ts.children[0].children[0].children).forEach(element => element.children[0].addEventListener('click', tabSelection)); } })