const contents = document.querySelectorAll('.content > div'); const buttons = document.querySelectorAll('.tabBtns button'); buttons.forEach((button, i) => { button.addEventListener('click', () => { buttons.forEach(button => button.classList.remove('active')); contents.forEach(content => content.classList.add('hide')); button.classList.add('active'); contents[i].classList.remove('hide'); }); });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter