-2

I have the following problem: I would like to add class="active" to the li matching the webpage I'm surfing on using javascript (I use jQuery library). I can't figure out how to do that, though I tried many examples found here and on other sites. So here is my html:

<header>
  <div id="menu" class="clearfix">
    <nav class="navigation">
      <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About</a></li>
        <li><a href="blabla.html">Bla</a></li>
        <li><a href="blablabla.html">Blablabla</a></li>
        <li><a href="blaX4.html">Tools</a></li>
        <li><a href="contact.html">Contact</a></li>
      </ul>
    </nav>
  </div>
</header>

Thank you very much! Any answer will be appreciated!

Andy
  • 61,948
  • 13
  • 68
  • 95
Akil
  • 3
  • 1
  • 2

1 Answers1

0

this should works just fine :)

   $(document).ready(function () {
            var url = window.location;
    $('.navigation ul li a[href="'+url+'"]').parent().addClass('active');
    });
Youness
  • 1,468
  • 1
  • 9
  • 19