-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add custom js to remove/add active class
Signed-off-by: Huong Nguyen <huongg1409@gmail>
- Loading branch information
Huong Nguyen
committed
Jun 24, 2024
1 parent
d080c55
commit 8051b9b
Showing
3 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
// Select all navigation links within the .wy-main-nav container | ||
var navLinks = document.querySelectorAll('.wy-main-nav .wy-main-nav-link'); | ||
|
||
// Function to remove 'active' class from all links | ||
function removeActiveClass() { | ||
navLinks.forEach(function(link) { | ||
link.classList.remove('active'); | ||
}); | ||
} | ||
|
||
// Add click event listener to each link | ||
navLinks.forEach(function(link) { | ||
link.addEventListener('click', function(event) { | ||
// Prevent the default link action | ||
event.preventDefault(); | ||
|
||
// Remove 'active' class from all links | ||
removeActiveClass(); | ||
|
||
// Add 'active' class to the clicked link | ||
event.target.classList.add('active'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters