Inactive blog. If you need anything, contact me : lloydalemania@gmail.com Hire me

Make your menu item active using this simple jquery

Today we will make a navigation menu item active using a very simple jQuery!

Introduction

This simple jQuery will check the URL of the current page and see if it matches with the URLs in the menu, then an "active" class will be added to the menu item automatically.

External Scripts

Jquery Library v1.0.0 or higher (?)

Live Demo

Demo

JScript

Go to Blogger » Template » Backup your Template » and Edit HTML
Copy the following code and paste it before </head>
<script>
 jQuery(document).ready(function($){
   var url = window.location.href;
     $(&#39;#header li a[href=&quot;&#39;+url+&#39;&quot;]&#39;).addClass(&#39;active&#39;);
 });
</script>
Save your Template!

Final Words

So that's it! Don't hesitate to ask. Enjoy blogging!
Hey! Did you find this tutorial useful? Share your thoughts by leaving a comment below!

0 Comments

Be the first to comment

[default]

mba-1

[enabled]

521946774841758

Mailing List

Sign up with your email address to receive news and updates straight in your inbox.