Skip to content
Advertisement

Simple accordion doesn’t work because handler fires 2 times at once

I’m trying to create a very simple accordion.

index.html

JavaScript

main.js

JavaScript

The first accordion works without any issue but when clicked one the second on the “toggle” function gets fired twice instantly making no difference. Any clue ?

Advertisement

Answer

First, you don’t need to write a toggle function for classList because it already exists.

Second, your <div class="body"> nodes need to have a closing </div> tag.

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