It is used on a <details> element, so your example with the <div> is not correct.
HTML5 Spec says:
The
opencontent attribute is a boolean attribute. If present, it indicates that both the summary and the additional information is to be shown to the user. If the attribute is absent, only the summary is to be shown.When the element is created, if the attribute is absent, the additional information should be hidden; if the attribute is present, that information should be shown. Subsequently, if the attribute is removed, then the information should be hidden; if the attribute is added, the information should be shown.
- Browser support for
<details> - And a little demo for fun
Videos
You can add the open attribute into the details tag like this:
<details open>
<summary>Table of Contents</summary>
<ul>
<li><a href="#" class="active">Introduction</a></li>
<li><a href="/2/">Body</a></li>
<li><a href="/3/">Conclusion</a></li>
</ul>
</details>
The details will then be expanded by default.
If you want a JS solution, you could give the details element an ID:
<details id="target-me">
<summary>Table of Contents</summary>
<ul>
<li><a href="#" class="active">Introduction</a></li>
<li><a href="/2/">Body</a></li>
<li><a href="/3/">Conclusion</a></li>
</ul>
</details>
And then use the following JS:
document.getElementById("target-me").open = true;