I've got an FAQ section on my page and it only displays the questions which can be clicked on to reveal the answers. The problem is when I click a question, it doesn't reveal the answer. I used to have it on another platform (Instapage) and it worked correctly there (see it in action here: http://www.legalcalls.com/#faq), but it doesn't here. This is the custom js code I have for it:
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight){
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
That's it. Before moving to WordPress, that did the trick on Instapage. I've added the js code in the Custom JS field in the Theme Options and all it seems to do is turn the + sign into a - sign whenever I click a question, but it doesn't reveal the answer.
I've got an FAQ section on my page and it only displays the questions which can be clicked on to reveal the answers. The problem is when I click a question, it doesn't reveal the answer. I used to have it on another platform (Instapage) and it worked correctly there (see it in action here: http://www.legalcalls.com/#faq), but it doesn't here. This is the custom js code I have for it:
var acc = document.getElementsByClassName("accordion"); var i;
for (i = 0; i < acc.length; i++) { acc[i].addEventListener("click", function() { this.classList.toggle("active"); var panel = this.nextElementSibling; if (panel.style.maxHeight){ panel.style.maxHeight = null; } else { panel.style.maxHeight = panel.scrollHeight + "px"; } }); }
That's it. Before moving to WordPress, that did the trick on Instapage. I've added the js code in the Custom JS field in the Theme Options and all it seems to do is turn the + sign into a - sign whenever I click a question, but it doesn't reveal the answer.
Am I doing something wrong?
Thank you!
Hi,
Why you don't use accordions included in the Wpbakery plugin?
Take a look here:
https://codex-themes.com/thegem/documentation/#toggles-and-accordion
Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list.
Regards, Oliver
I'm still getting the hang of everything, didn't even notice WPBakery had an Accordion. Thank you so much!
Welcome!
Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list.
Regards, Oliver