Here I have a list, what I want to do is I need to change the list ( li ) background color to different one after click on a specific list item. the thing is once it click on the link page will be redirected and refresh. please can me suggest a solution for to get this done?
<div id=main-menu>
<ul id=main-menu-list>
<li id=menu-home><a href=main/home>Home</a></li>
<li id=menu-profile><a href=main/profile>My Profile</a></li>
<li id=menu-dashboard><a href=main/db>My Dashboard</a></li>
<li id=menu-search><a href=main/search>Search</a></li>
</ul>
</div>
what i did for this :
Java Script :
var make_button_active = function()
{
//Get item siblings
var siblings =($(this).siblings());
//Remove active class on all buttons
siblings.each(function (index)
{
$(this).removeClass('active');
}
)
//Add the clicked button class
$(this).addClass('active');
}
//Attach events to menu
$(document).ready(
function()
{
$(#main-menu li).click(make_button_active);
}
)
CSS :
#main-menu-list li.active {
background: #0040FF;
}