Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why the accordion is not working in this case?

I tried to make a accordion using HTML, CSS and JavaScript. The HTML and CSS is working well but the javaScript emplementation is not working. Can someone help me?

Files are here: https://drive.google.com/drive/folders/1nzEyyU_4QA4x_qh1QE_rz3V3DD_r7PAv?usp=sharing

I can’t add code snippets because the stack overflow is not letting me submit the question.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here is a working script for you. Replace this with your javascript.

Working example I made on Codepen:
https://codepen.io/9to5disappear/pen/jOYBJJp

Javascript:

'use strict'

let label = document.getElementsByClassName('label');
let content = label.nextElementSibling;


const elements = document.querySelectorAll('.content');
Array.from(elements).forEach((element, index) => {
    element.parentElement.addEventListener('click', () => {
        element.classList.toggle('content-visible');
    })   
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading