Build a help page with no JavaScript in your HTML.
What to build
An accordion, a dialog and a template.
Requirements
- Three
detailselements withname="faq"and summariesShipping,ReturnsandPayment, each with a paragraph. - The first starts open.
- A
dialogwithid="contact", containing aformwithmethod="dialog"and abuttonreadingClose. - A
templatewithid="row", containing oneliwith the classresult.
Constraints
Nothing from the template may be displayed.
Example
<details name="faq" open> starts open, and closes when another in the group opens.
Why it works
Sharing the name gives the accordion behaviour for free. The dialog closes without a script, and a template holds markup that scripts can copy later.
Hints
Hint 1
details elements with the same name act as an accordion.
Hint 2
The dialog needs a form with method="dialog".
Hint 3
A template stays hidden, so it can hold a repeated row.
Solution
Show one correct solution (try it yourself first)
<h1>Help</h1> <details name="faq" open><summary>Shipping</summary><p>Two days.</p></details> <details name="faq"><summary>Returns</summary><p>Within 7 days.</p></details> <details name="faq"><summary>Payment</summary><p>Card or cash.</p></details> <dialog id="contact"> <form method="dialog"><button>Close</button></form> </dialog> <template id="row"><li class="result"></li></template>