Coding⏱️ 2 min read📅 2026-05-31

How to Fix: Bootstrap navbar Active State not working

Bootstrap navbar Active State not working issue with v3. Solution involves checking jQuery inclusion and executing JavaScript code after DOM load.

Quick Answer: Verify jQuery inclusion and ensure JavaScript code runs after DOM is loaded.

Bootstrap navbar's active state not working can be frustrating, especially when you're new to the framework. In this guide, we'll explore why this issue occurs and how to fix it using a simple JavaScript solution.

🔍 Why This Happens

  • Bootstrap navbar's active state is not enabled by default. It relies on JavaScript to toggle the classes.

🚀 How to Resolve This Issue

Method 1: Enabling Bootstrap's Navbar Active State

  1. Step 1: Add the active-class attribute to your navbar's li elements.

Method 2: Using JavaScript to Enable Active State

  1. Step 1: Add the following code inside your <body> tag:

Example Code

<script src="/bootstrap/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
''$('.nav li')'.on('click,', function() {
$(this).closest('.nav').addClass('active');
});
''$('.nav li.active')'.on('click,', function() {
$(this).closest('.nav').removeClass('active');
});
''$('.nav li')'.on('click,', function() {
$(this).closest('.nav').removeClass('active');
});
''$('.nav li.active')'.on('click,', function() {
$(this).closest('.nav').addClass('active');
});
''$('.nav li')'.on('click,', function() {
$(this).closest('.nav').removeClass('active');
});
</script>

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions