This issue is kinda similar with this post, but mine is just a simple highlighting one of the menu item by adding a CSS class.
Basically, I'm trying to loop through a list of menu item under #nav-accordion
div. When the IF condition is true, I will append active
class to the li
element.
Here is my code
$("#nav-accordion li a").each(function () {
if (true) {
$(this).closest("li").addClass("active");
// Expand the parent menu
$(this).closest("li").closest("ul").show();
// Highlight the parent menu item
$(this).closest("li").parent().parent().find("a").addClass("active");
// Exit loop when one of the menu item is highlighted
return;
}
}
When I load the page without developer tool open in Chrome, the highlight does not work; but when I open the developer tool and load the page, the highlighting work like a magic. Now I don't know how this strange magic work.
This post describe that I should remove any console.log
in the code, which I did. But the same problem still persist.
Any idea?