I have created a toggle menu that displays a list of child elements when clicked, and hides them if clicked again.
However, when a child element is clicked, I want it to navigate to the corresponding page. I am having trouble getting this functionality to work. Could it be related to my use of preventDefault?
// Language select in global nav
$('.sub-lang').on('click', function(e) {
if ($(this).hasClass('active') && $(e.target).parent().hasClass('active')) {
$(this).removeClass('active');
$(this).css('height', 'auto');
$(this).children('ul').hide();
} else {
$(this).addClass('active');
$(this).css('height', $(this).find('ul').height() + 65);
$(this).children('ul').show();
}
e.preventDefault();
});
You can view the code on JsFiddle.