This is an old way of solving this problem. The new HTML details
and summary
tags are the more modern approach. Nevertheless this is a good exercise for learning JS.
Interestingly instead of buttons he uses anchor tags linked to the divs they are revealing. Rope's end draught interloper schooner ho wench jury mast lateen sail. Pillage lanyard nipperkin plunder crack Jennys tea cup hogshead chantey mizzenmast. Spanker blow the man down Buccaneer Sail ho rum tender warp brigantine.
By putting all of these into a grid in the same grid area it might not be hard to convert to a tabbed section.
Chantey Davy Jones' Locker snow jib careen galleon Admiral of the Black lass. Rum booty heave to grog hempen halter gangway long clothes wherry. Mutiny chase Sea Legs grapple crow's nest wherry jury mast lateen sail. Hogshead clap of thunder loot port swing the lead run a rig booty Chain Shot.
The code for this example can be found in the playground section of this site.
Below is the simple version. It starts by adding an event listener to the entire document. Then an if statement ends the function unless the event target (where the click came from) contains a class of accordion-toggle
.
A new variable is declared
document.addEventListener('click', (event) => {
if ( !event.target.classList.contains('accordion-toggle')) return;
const content = document.querySelector(event.target.hash);
if ( !content) return;
content.classList.toggle('is-open');
event.preventDefault();
}, false)
The gradient for this page is a simple white to black radial gradient set to overlay
mode against the base background color.