A basic JavaScript and HTML accordion.
When coding something like a JavaScript accordion, half of the problem is how to split the lager objective into small steps. Download a copy of the index.html
and accordionjs
files and then follow these steps. Do not proceed to the next step until the current one is done and tested.
- Use CSS to hide all sections of content.
- Add a click event to the section titles. For now
console.log()
the word "open". - Function needs to know which section was clicked. Use
console.log()
to confirm. - On
click
, make the content below the link visible. - Use an
if
statement to hide or display the content. - Hide all other accordion content before displaying the new content.