I have built a custom toggle menu using Javascript:
$(document).ready(function() {
$('.toggle').click(function () {
if ($(this).hasClass("expanded")) {
$(this).next().slideUp("fast");
} else {
$('.toggle').next().slideUp("fast").removeClass("expanded");
$(this).next().slideDown("fast");
$(this).removeClass("collapsed");
$(this).addClass("expanded");
}
});
});
However, I am facing an issue where clicking on another menu item does not remove the "expanded" class from the other elements. I've tried various solutions but can't seem to figure it out. Any assistance on this problem would be greatly appreciated.