Design comparison
Solution retrospective
I used Html, Css and Javascript but not sure if the Html semantic structure is correct, also the user is able to open all answers at once but is it better to allow them to open a single answer at time instead? Any feedback is very welcome.
Community feedback
- @Ogshabzy23101Posted 10 months ago
i will suggest you add eventlistener to each button and target the granparent element of each button, then toggle the class list of hidden. then also check under the button event listener if each granparent equals to the current granparent, if it does then remove the hidden class
const quesContainer = document.querySelectorAll('.ques-container')
const btns = document.querySelectorAll('.btn')
btns.forEach(function (btn) {
btn.addEventListener('click', function (e) {
const question = e.currentTarget.parentElement.parentElement
quesContainer.forEach(function (newQuestion) { if (newQuestion !== question) { newQuestion.classList.remove('show-text')
} })
question.classList.toggle('show-text')
})
})
i hope the is helpful, please rate my suggestion. thanks
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord