As I develop the navigation bar for my website, I am faced with a challenge. I want to create a button-like behavior where clicking on an li
element triggers a drop-down section underneath it without using the #
attribute to prevent jumping to the top of the page. While researching online, I came across two different jQuery snippets:
$('li').click(function() {
$(this).siblings().removeClass('active');
$(this).addClass('active');
});
and
$('li').click(function() {
$(this).addClass('active').siblings().removeClass('active')
});
Despite trying various modifications like adding multiple classes or changing the active class to an id
, I have not been able to get the desired outcome.
Interestingly, when testing this code on platforms like CodePen or JSFiddle, it works perfectly fine. However, I encounter issues when running it in my own browser using the VisualStudio emulator.
If you would like to view the code snippet with the navigation bar, you can access it here: http://codepen.io/PorototypeX/pen/sjDBL