My JSFiddle
I have multiple links and I want to have same hover effect on all the links, is there any simple way to do it. I wrote Javascript for one ID, but I don't want to write for all links. When hovered, the link text should change to white and background color should change to red.
CSS
ul {
list-style-type: none;
}
li {
margin-bottom:5px;
width:100px;
}
ul li a{
text-decoration:none;
color:black;
}
HTML
<div style='padding:10px;border:2px solid red'>
<ul>
<li id='llist'><a href='#' id='list'>List</a></li>
<li id='lgroups'><a href='#' id='groups'>Groups</a></li>
<li id='lprofile'><a href='#' id='profile'>Profile</a></li>
<li id='linvitations'><a href='#' id='invitations'>Invitations</a></li>
</ul>
<h5 style='color: white'>PROJECTS</h5>
<ul>
<li id='lsummary'><a href='#' id='summary'>Summary</a></li>
<li id='ltrack'><a href='#' id='track'>Track</a></li>
<li id='lmanage'><a href='#' id='manage'>Manage</a></li>
<li id='lexport'><a href='#' id='export'>Export</a></li>
</ul>
<h5 style='color: white'>ANALYSIS</h5>
<ul>
<li id='lanalyse'><a href='#' id='analyse'>Analyse</a></li>
<li id='lviewall'><a href='#' id='viewall'>ViewAll</a></li>
<li id='lexport'><a href='#' id='export'>Export</a></li>
</ul>
<h5 style='color: white'>SETTINGS</h5>
<ul>
<li id='lusers'><a href='#' id='users'>Users</a></li>
<li id='larchive'><a href='#' id='archive'>Archive</a></li>
<li id='lsystem'><a href='#' id='system'>System</a></li>
<li id='lmyprofile'><a href='#' id='myprofile'>My Profile</a></li>
</ul>
</div>
JS
$(document).ready(function(){
$('#list').hover(
function(){
$(this).css('margin-left','10px');
$(this).css('color','white');
$('#llist').css('background-color','red');
},function(){
$(this).css('margin-left','0px');
$(this).css('color','black');
$('#llist').css('background-color','white');
}
);
});
NOTE: Here I gave 'a' tag, may be it will become easy with a: hover, a: link etc. Also write the answer keeping in mind such that, it will be applicable to all.
:hover? I understand this question is tagged withjavascriptandjquerybut still CSS will be the obvious choice since you also mention 'same hover effect on all links'.