brooklyndesignstudio

Anchor Link Menu Highlighting

Jun 12th, 2019
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--  Anchor Link Highlighting  -->
  2. <script>
  3. (function ($) {
  4.     $(document).ready(function () {
  5.         var current_page = window.location.href;
  6.         var menu_items_links = $(".nav li a"); 
  7.         menu_items_links.each(function () {
  8.             $(this).parent().removeClass('current_page_item current-menu-item');
  9. $('.nav li a[href="'+current_page+'"]').parent().addClass('current_page_item current-menu-item');          
  10.                 $(this).click(function () {
  11.                     menu_items_links.parent().removeClass('current_page_item current-menu-item');
  12.                     $(this).parent().addClass('current_page_item current-menu-item');
  13.                 })
  14.  
  15.         })
  16.     });
  17. })(jQuery);
  18. </script>
RAW Paste Data