Skip to content
Advertisement

Automatically close all the other tags after opening a specific tag

Here is my code.

JavaScript

What I want to do is — if the details of any single <details> tag is open and I open/view another <details> tag, then the earlier one should close/hide/minimize.

How can this be achieved?

I’m aware the <details> tag is not supported in IE or Edge.

Advertisement

Answer

Another approach, slightly shorter, slightly more efficient, without dependencies, and without onclick attributes in the HTML.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement