Currently, I am in the final stages of developing my custom Jquery accordion. However, I am facing a challenge with having it start in a closed position without explicitly using $(".wrap-faq li p").slideUp();
before the function, as it automatically slides up upon loading.
My goal is to have the accordion load with all sections closed. While attempting to achieve this through CSS using display:none;
and visibility: hidden;
, unfortunately, both methods proved ineffective. Below is a snippet of my Jquery code:
$(".wrap-faq a").on("click", accordion);
$(".wrap-faq li p").slideUp();
function accordion() {
if ($(this).attr("class") != "active") {
$(".wrap-faq li p").slideUp();
$(this).next().slideToggle();
$(".wrap-faq a").removeClass("active");
$(this).addClass("active");
}
}
For further reference, you can view the jsFiddle link by clicking here.