How To Activate The Menu On The Display Section Using Jquery

In this topic,

We are going to see how to activate the menu on the display section using jQuery and how to redirect the menu on the section.

Step-1: include the jQuery link in the <head>..</head>tag on index.html file.

<script src=""></script>

Step-2: Create Html Code in the index.html file.

      <div class="collapse" id="navbarSupportedContent">
         <ul class="navbar-nav">
           <li class="nav"><a href="#slider" class="sedo" style="font-size:18px">Home</a></li>
           <li class="nav"><a href="#about" class="sedo" style="font-size:18px">About Us</a></li>
           <li class="nav"><a href="#gallery" class="sedo" style="font-size:18px">Gallery</a></li>
           <li class="nav"><a href="#menu" class="sedo" style="font-size:18px">Menu</a></li>
           <li class="nav"><a href="#reservation" class="sedo" style="font-size:18px">Reservation</a></li>
           <li class="nav"><a href="#contact" class="sedo" style="font-size:18px">Contact Us</a></li>
  <div class="all-sections">
    <div class="slider test">
      <div class="section1" id="slider">
    <div class="about-us test">
      <div class="section2" id="about">
        <h2>About Us</h2>
    <div class="gallery">
      <div class="section3" id="gallery">
    <div class="menu">
      <div class="section4" id="menu">
    <div class="reservation">
      <div class="section5" id="reservation">
    <div class="contact">
      <div class="section6" id="contact">
        <h2>Contact Us</h2>

Step-3: Add CSS in<style>….</style> tag on index.html file.

  margin: 0;
  text-align: center;
  background-color: #54595F;
  margin: 0;
ul li.nav{
  display: inline-block;
ul li.nav a{
  color: #fff;
  text-decoration: none;
  padding:0 25px;
.section1,.section3,.section5 {
  background-color: #ccc;
  background-color: #efefef;
.all-sections h2{
  font-size: 35px;
  margin: 0;
  position: fixed;
  margin: 0;
  width: 100%;
.navbar ul li .elementor-icon-list-text{
  color: #000 !important;
.navbar-nav .nav{
  background : #a98e8e;
  color : #fff;
  padding: 15px;

Step-4: Add jQuery code in <script>…</script> tag on index.html.

In this code, I get the top Position and add the active class to the menu when the Position of the top and the Position of the section are equal.

$(window).scroll(function() {
  var scrollPos = $(document).scrollTop();
    $('.navbar-nav .nav a').each(function () {
        var testmenu = $($(this).attr("href"));
        if (testmenu.position().top - 60 <= scrollPos) {
            $('.navbar-nav .nav a').removeClass("active-menu");

Review the below video.

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories