-1

I have a style:

.web_show_webcam:hover{color:#000;background:#fff;}

How to attach this css to element using JQuery? This way doesn't work:

$(".web_show_webcam").addClass("web_show_webcam:hover");
splash27
  • 2,057
  • 6
  • 26
  • 49
  • :hover selector will work if you load element with class. You dont have to add it using jQuery. http://jsfiddle.net/kunknown/gjdqt0yn/ – Kiran Sep 19 '14 at 13:38

2 Answers2

0

You can try like this:

$(".web_show_webcam").hover(function() {
  $(this).css("background-color","red")
});
Java_User
  • 1,303
  • 3
  • 27
  • 38
  • 1
    True, but that really isn't answering the question. You show how to add a hover effect, but you don't explain whether it's possible, or how to, add the CSS pseudo class using jQuery. – j08691 Sep 19 '14 at 13:56
  • Wouldn't it make sense to just add an hover effect instead of adding the pseudo class. that way he can save some bytes. But again if that is what Op is asking then he/she might rethink on the approach. – Java_User Sep 19 '14 at 13:59
-1
$('#btn').mouseover(function(e){
    $(this).addClass('hoverState');
}).mouseout(function(e){
    $(this).removeClass('hoverState');
});

try JSFiddle

ibrahimyilmaz
  • 2,317
  • 1
  • 24
  • 28