Skip to content

Close one accordion item when another opens #778

Answered by onemanwenttomow
gregorsart asked this question in Web
Discussion options

You must be logged in to vote

Firstly, kudos on your work so far—it's a commendable effort!

I'd like to introduce you to some hidden gems in HTML— the details and summary tags. These elements offer built-in functionality for creating accordions without the need for javascript. They handle a significant part of the heavy lifting.

To implement this, you just need to keep track of an identifier (like an id or index) for the currently open detail. I've put together an example for you to take a look at here.

It's worth noting that there's an exciting feature on the horizon (see here), which promises to make this process even more straightforward. However, keep in mind that, as of now, this functionality is not universally …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@gregorsart
Comment options

Answer selected by onemanwenttomow
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
2 participants