0

I have an anchor tag with some css hover selection property assigned. This CSS is auto-generated by the system.

a.abcClass{
    color: GREEN;
}
a.abcClass:hover{
    color: RED;
}

I would like to assign above given hover CSS dynamically using jQuery. Like I would like to achieve this:

$("a.abcClass").addClass(":hover")

How this can be done ?

Edit: hover properties will be applied only when mouse will be hover over that element. What if I want to have hover effect on anchor tag when some button is clicked. As this CSS is autogrnerated I don't know about its css properties.

Nav Ali
  • 1,232
  • 6
  • 17
  • 26

3 Answers3

0

Will this work?

$('.abcClass').css('color','red');
hungerstar
  • 21,206
  • 6
  • 50
  • 59
0

Handle Hover state using jQuery:

$(function() {
    $('.abcClass').hover( function(){
          $(this).css('color', 'red');
    });
});

Handle both states using jQuery:

$(function() {
   $('.abcClass').hover( function(){
      $(this).css('color', 'red');
   },
   function(){
      $(this).css('color', 'green');
   });
});

Sample Fiddle: http://jsfiddle.net/VcEf4/

Learner
  • 3,904
  • 6
  • 29
  • 44
-1
a.abcClass{
    color: GREEN;
}
a.abcClass:hover, .my_epic_stylez {
    color: RED;
}

And:

$(".my_epic_stylez").addClass(":hover");

You can't add pseudo-classes like you are trying to do. The same goes for adding :before and :after-classes too.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
  • Yeah I know I cant add, I am just giving example of what I am trying to achieve (with some other syntax). – Nav Ali Jul 04 '13 at 19:45