I have an accordion menu, when the link header is clicked, it loads the page with the secondary links.
When clicked the .on('click')
is loaded before the HTML elements are loaded, so I have to click the link header twice to open the accordion menu.
$('.accordion-menu > li > a').on('click', function (e) {
if ($(this).siblings('ul').length) {
e.preventDefault();
if ($(this).closest('li').hasClass('active')) {
$(this).siblings('ul').slideUp('normal', function () {
$(this).closest('li').removeClass('active');
});
} else {
$(this).closest('.accordion-menu').find('> li.active ul').slideUp('normal', function () {
$(this).closest('li').removeClass('active');
});
$(this).siblings('ul').slideDown('normal', function () {
});
$(this).closest('li').addClass('active');
}
}
});
HTML
When I click the header, it should load the page and add class active as below
But now it actually just loads the page and elements are created, class active is not added.
See below "Find Jobs"
So in the JQuery function ($(this).siblings('ul').length
) is coming 0 first time, so no class is being added...
When I click the header second time, class is added and accordion is working fine.
I tried changing the $('.accordion-menu > li > a').on('click',function (e) {
but not helping...
Tried adding the function in XSLT (end of the file), currently its in separate JS file.
Thanks