Knowledge Walls
John Peter
Pune, Maharashtra, India
How to add active class to current page link using JQuery
11824 Views
HTML
<ul>
    <li>
        <a href="http://www.knowledgewalls.com/realtimejqueryeditor" class="main_anchor">Data</a>
    </li>
    <li>
        <a href="http://www.knowledgewalls.com/realtimejqueryeditor" class="main_anchor">Data</a>
    </li>
    <li>
        <a href="http://www.knowledgewalls.com/realtimejavascripteditor" class="main_anchor">Data</a>
    </li>
    <li>
        <a href="http://www.knowledgewalls.com/realtimehtmleditor" class="main_anchor">Data</a>
    </li>
    <li>
        <a href="http://www.knowledgewalls.com/realtimejqueryeditor" class="main_anchor">Data</a>
    </li>
</ul>
CSS
.colorIt {
   background-color: yellow;
}
JQuery 
$(function(){
   $('a[href^="'+document.location+'"]').parent().addClass("colorIt");
});
Demo 
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details