Title: Highlight current section
Last modified: August 17, 2021

---

# Highlight current section

 *  [Phil](https://wordpress.org/support/users/imatoni/)
 * (@imatoni)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/highlight-current-section-2/)
 * Hi,
 * I would like to know, if and how it is possible to highlight the current headline
   depending on where there the browser scroll is right now.
 * Would be great if there’s class on the current headline.
 * Any ideas?
 * Thanks !

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Phil](https://wordpress.org/support/users/imatoni/)
 * (@imatoni)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/highlight-current-section-2/#post-14777625)
 * I was able to solve it myself.
 * Was only a little bit of jQuery code
 * If it can help anyone else here is my code:`
 *     ```
       jQuery( document ).ready(function() {
   
           jQuery(window).scroll(function(){
               var scrollTop = jQuery(document).scrollTop();
               var anchors = jQuery('body').find('.ez-toc-section');
   
               offset_1 = 150;
               offest_2 = 1;
   
               for (var i = 0; i < anchors.length; i++){
   
                   if (scrollTop > jQuery(anchors[i]).offset().top - offset_1 && scrollTop < jQuery(anchors[i]).offset().top + jQuery(anchors[i]).height() - offest_2) {
                       jQuery('nav ul li a').removeClass('active');
                       jQuery('nav ul li a[href="#' + jQuery(anchors[i]).attr('id') + '"]').addClass('active');
                   }
   
               }
           });
   
       });
       ```
   
 * You can adjust the ofset_1 and offset_2 to adjust when a new highlight should
   be triggered. Replace ul with ol if you have an ordered list.
 * Source [https://stackoverflow.com/questions/65954297/highlighting-item-in-table-of-contents-when-section-is-active-on-page-as-scrolli](https://stackoverflow.com/questions/65954297/highlighting-item-in-table-of-contents-when-section-is-active-on-page-as-scrolli)
   and [https://stackoverflow.com/questions/26382551/making-a-menu-class-active-when-scrolled-past](https://stackoverflow.com/questions/26382551/making-a-menu-class-active-when-scrolled-past)
    -  This reply was modified 4 years, 9 months ago by [Phil](https://wordpress.org/support/users/imatoni/).
    -  This reply was modified 4 years, 9 months ago by [Phil](https://wordpress.org/support/users/imatoni/).
 *  [webnature](https://wordpress.org/support/users/webnature/)
 * (@webnature)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/highlight-current-section-2/#post-15163569)
 * Many thanks for the jquery code. You made my day [@phil](https://wordpress.org/support/users/phil/).
   
   God bless you.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Highlight current section’ is closed to new replies.

 * ![](https://ps.w.org/easy-table-of-contents/assets/icon-256x256.png?rev=3045459)
 * [Easy Table of Contents](https://wordpress.org/plugins/easy-table-of-contents/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/easy-table-of-contents/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/easy-table-of-contents/)
 * [Active Topics](https://wordpress.org/support/plugin/easy-table-of-contents/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easy-table-of-contents/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easy-table-of-contents/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [webnature](https://wordpress.org/support/users/webnature/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/highlight-current-section-2/#post-15163569)
 * Status: not resolved