I need to highlight the clicked navbar with active class

add active class onclick javascript
active class in css menu
bootstrap navbar active class jquery
bootstrap active class on click
bootstrap 4 navbar active color
css active after click
highlight current page in menu with javascript
jquery add active class to current menu item

This is my Navbar code:

<div class="navbar-collapse offcanvas-collapse justify-content-md-center" id="navbarsExampleDefault">
  <ul class="navbar-nav">
    <li class="nav-item active">
      <a class="nav-link" href="@Url.Action(" DashBoard ","Admin ")">Dashboard</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="@Url.Action(" SectionsList ","Admin ")">Sections</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="@Url.Action(" DifficultyList ","Admin ")">Difficulty</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="@Url.Action(" QuestionsList ","Admin ")">Questions</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="@Url.Action(" AssessmentList ","Admin ")">Assessments</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="@Url.Action(" UsersList ","Admin ")">User's</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Students</a>
      <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="nav-link" href="@Url.Action(" StudentResult ","Admin ")">Student Results</a>
      </div>
    </li>
  </ul>
</div>

This is my click function:

$("#navbarsExampleDefault li a").click(function() {
    $(this).parent().addClass('active').siblings().removeClass('active');
});

I need to highlight the selected navbar with active class. I have tried this one but not working

public ActionResult SectionsList()
 {
  return view();
}

This is one of my action method


var change = function () {
    var url = window.location.pathname;        
    $('ul.navbar-nav a[href="' + url + '"]').parent().addClass('active');        
};
change();

Load this function in the js file which is common to every page and remove class active from li. Works even when the page reloads.

I hope it works for you! Thanks!

Highlight active class in nav-bar, var change = function () { var url = window.location.pathname; $('ul.navbar-nav a[ href="' + url + '"]').parent().addClass('active'); }; change();. Load this function in� Following examples illustrates how to add active class on click event in custom list group using jQuery in different ways. Example 1: Below example illustrates how to add active class on click event in custom list group using jQuery through for loop.


Place the below edited piece of code which is tested

$(document).ready(function(){
$(".navbar-nav .nav-link").click(function (e) {
     e.preventDefault();
    $('.nav-item').removeClass('active');
    $(this).closest('.nav-item').addClass('active');
 });
});

How To Add Active Class To Current Element, The javascript to highlight the active nav-item in a nav-bar based on the "active" class. Now, you see a class named #nav ul li .active this is not yet added to any of the navigation items. To add it, we need to add some jQuery to our project, that will check the page URL that the user or visitor is viewing, and compares with the one on the menu item. If they mach, it’ll add the .active class to that menu item.


Please use below code

$("#navbarsExampleDefault li a").click(function () {
    $('.nav-item').removeClass('active');
    $(this).parent().addClass('active');
 });

Hope it works for you Thanks!

Navigation: highlighting the current page, Loop through the buttons and add the active class to the current/clicked button for (var i = 0; i < btns.length; i++) { btns[i].addEventListener("click", function() { This is my click function: $("#navbarsExampleDefault li a").click(function() { $(this).parent().addClass('active').siblings().removeClass('active'); }); I need to highlight the selected navbar with active class. I have tried this one but not working. public ActionResult SectionsList() { return view(); } This is one of my action method


Assign "active" class to navbar item based on current page URL with , Highlighting the current page in our navigation to denote which page we're How can I make Duration: 2:45 Posted: Feb 18, 2015 Assign "active" class to navbar item based on current page URL with jQuery - footer.js


Bootstrap Navbar Change Active Class Link, get current URL path and assign 'active' class. var pathname your average Bootstrap navbar component, in this case placed in an include called header. html --> I have a question. How do I assign the $('ul li a').click(function(){ $(' li a'). Many thanks for the advice, though I may not have explained my problem very well. I don't need the items in the dropdown submenu to remain highlighted, I need the top level item to remain highlighted when a dropdown item is selected.


Highlight Active Menu Item With jQuery Script, <div class="navbar-header">. 5. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" � Highlighting the current page in our navigation to denote which page we’re currently viewing. Add Remove Active Class On Click - Html CSS and Adding an active class link to menu items