Hi. I have two accordions on my page. They are identical except that content is a little different in the second accordion. Accordion 1 will show on large screens, accordion 2 hidden. Vice Versa on mobile. Each accordion has two panels, The first panel is open onload, the second panel closed. When the second panel is opened, this goes for both accordions, it displays a tabbed section, where the first tab is selected and the content shown.
Everything mentioned above works. The problem is when i select any of the other tabs in the second panel of accordion 2, which only shows on mobile, the tab changes but the content for that tab doesn’t display. If I go back to the first tab that was selected by default onload and displayed the tab content, it no longer shows the content. Also, when you try to close the second panel, it slides up, then goes right back down into open position.
Again, just for clarity, my first accordion does everything perfectly. The second accordion is having the problems.
Here is my script:
Accordion 1 (Large Screen)
$(".desc").hide();
$(".desc:first").show(); // THIS LINE IS ADDED!!!
$("h3.open-close").click(function(){
if ($(this).is(".current"))
{
$(this).removeClass("current");
$(this).next(".desc").slideUp(400);
}
else
{
$(".desc").slideUp(400);
$("h3.open-close").removeClass("current");
$(this).addClass("current");
$(this).next(".desc").slideDown(400);
}
});
Accordion 2 (Mobile Screen)
$(".desc2").hide();
$(".desc2:first").show(); // THIS LINE IS ADDED!!!
$("h3.open-close").click(function(){
if ($(this).is(".current2"))
{
$(this).removeClass("current");
$(this).next(".desc2").slideUp(400);
}
else
{
$(".desc2").slideUp(400);
$("h3.open-close").removeClass("current");
$(this).addClass("current");
$(this).next(".desc2").slideDown(400);
}
});