I have defined an <a>
tag with css. I'm trying to stop default stylesheet :hover
changes on the a
tag. How do I disable the hover changes on the a tag in Jquery?
views:
372answers:
4
+3
A:
Live demo of the following solution: http://jsbin.com/umiru
--
The easiest way I can think of is to change:
a:hover { ... }
into
a.someClass:hover { ... }
And then add/remove .someClass
via jQuery's methods:
$(this).addClass("someClass"); // activates css rules for :hover
$(this).removeClass("someClass"); // deactivates css rules for :hover
Jonathan Sampson
2010-01-13 01:06:49
tried that not work
zsharp
2010-01-13 01:11:49
Do you mean your stylesheet has `a:hover { color:red }` or something similar?
Jonathan Sampson
2010-01-13 01:12:23
yes thats it hhh
zsharp
2010-01-13 01:13:34
zsharp - see my updates please.
Jonathan Sampson
2010-01-13 01:20:36
zsharp - the solution I provided works. Please see the link included at the top of my solution for a demonstration.
Jonathan Sampson
2010-01-13 01:47:58
+1
A:
The easiest way would be to create a new CSS rule for the specific a tag. Something like
a.linkclass:hover {color:samecolor}
If you have to use JQuery to override the default styles, you have to manually add the css rules in the hover state, something like this:
$('a.linkclass').hover(function(){
$(this).css({'color':'samecolor'});
});
hope this help
honeybuzzer
2010-01-13 01:15:57
A:
Just define your CSS without a "a:hover"
a { color: #fffff }
This CSS will override the a:link, a:hover, a:visited and a:active.
fudgey
2010-01-13 02:05:22
A:
Here is a solution without hack classes:
CSS:
a {color: blue;}
a:hover {color: red;}
jQuery (uses jQueryUI to animate color):
$('a').hover(
function() {
$(this)
.css('color','blue')
.animate({'color': 'red'}, 400);
},
function() {
$(this)
.animate({'color': 'blue'}, 400);
}
);
kingjeffrey
2010-07-18 15:50:45