Highlight Active Page in a Masterpage Menu

Highlight Active Page in a Masterpage Menu

If you have a menu inside a masterpage (in a ASP.NET Web site), you can highlight active page in masterpage menu and submenus using mentioned below javascript.

If you have a menu inside a masterpage (in a ASP.NET Web site), you can highlight active page in masterpage menu and submenus using mentioned below javascript.

Copy this script code and Paste it into your MasterPage:



Javascript:
<script>

          $(function () {
              var current_page_URL = location.href;
              $("a").each(function () {
                  if ($(this).attr("href") !== "#") {
                      var target_URL = $(this).prop("href");
                      if (target_URL == current_page_URL) {
                          $('nav a').parents('li, ul').removeClass('active');
                          $(this).parent('li').addClass('active');
                          return false;
                      }
                  }
              });
          });
          </script>

Result:

Share this

Related Posts

Previous
Next Post »