Collapsible alerts
Purpose
Plugin to enable the .alert class to be used with the details/summary elements. This allows the creation of alerts which can be collapsed by the user. The plugin uses Local Storage to enable the browser to remember the state of the alert (open or collapsed) when loading a page.
Working example
How to implement
To use collapsible alerts, your details/summary block must have the following:
-
The
detailselement must:-
Use a valid
.alertclass:
e.g.alert alert-success. -
Have an
idattribute with a unique value. Reuse this value for all the pages where you want the state of the alert to be remembered. For example, if a user collapses the alert ofidvalue “alert-123” on page A and navigates to page B where the same alert with theidvalue “alert-123” exists, the alert will already be collapsed upon loading the page. -
Have an
openattribute for its default state to be open. Omitting theopenattribute will cause the default state of the collapsible alert to be closed.
-
-
The
summaryelement must have a class matching that of its children element for the pointer (the triangle) to have the correct size. For instance, when using anh3element, thesummaryelement should have anh3class. -
Finally, every collapsible alert should be contained within a
sectionelement and have a heading for thesummaryelement's child.
<section>
<details class="alert alert-success" id="alert-success" open="open">
<summary class="h3">
<h3>Well done!</h3>
</summary>
<p>You successfully read <a href="#" class="alert-link">this important alert message</a>.</p>
</details>
</section>
Source code
- Date modified: