Reputation: 12441
How do I use jquery to achieve hover effect on a link that is normally down with css :hover, so when I hover over a link it changes to a different color, and when my mouse leaves the link it returns to the color it had before?
Edit My link has an inline style that sets its color, so I tried add and remove class they don't work, it seems the newly added css class cannot override the inline style.
Upvotes: 1
Views: 3293
Reputation: 12684
A simple way just use jQuery.hover()
:
$('a#mylink').hover(function(){$(this).toggleClass("underline");},function(){$(this).toggleClass("underline");});
or
$('a#mylink').hover(function(){$(this).css("text-decoration","underline");},function(){$(this).css("text-decoration","none");});
Upvotes: 3
Reputation: 22770
use the mouseenter and mouseleave events.
$("#linkname").mouseenter(function(){
$(this).addClass("highlight");
});
$("#linkname").mouseleave(function(){
$(this).removeClass("highlight");
});
mouseover, mouseout will also work.
for the link you can use the id with the # or class name with the .
so
so you can then use;
$("#anchorid").mouseleave(
or
$(".anchorclass").mouseleave(
Upvotes: 2