Styling active anchor with jquery

By: Arshad

17 Jan 2010

Snippet to add a class to the current active link for styling with css.

  1. $(document).ready(function(){
  2. //set class active-anchor to active anchor
  3. $('a').each(function(){
  4. if($(this).attr('href')==window.location.search)
  5. $(this).addClass('active-anchor')
  6. });
  7. });

There you go. Now the anchor that points to the current page will have the class active-anchor. You can style it in you css using .active-anchor.

About Me

Arshad Chummun Hello I'm Arshad. I'm a 21 years old Drupal Web Developer. This is a site i put up for some reasons i can't remember and this is where i write stuffs i need to remember.;)

In the Web world, i head the Drupal Mauritius User Group and the jQuery user Group Mauritius and i'm a campus representative for Mozilla Firefox. 

DrupalCon CPH 2010

Copenhagen August 23 -27

Drupalcon CPH 2010