CSS hover selector for background-color not working after dynamic change of background-color with jquery

前端 未结 5 1218
臣服心动
臣服心动 2020-12-15 17:06

I dynamically change the background color of a div with the jquery .css() method. I also want to have a CSS hover selector on that same div that ch

5条回答
  •  醉酒成梦
    2020-12-15 17:36

    When you manipulate css with jQuery it adds it inline and overrides any css in a stylesheet try using jquery to add and remove a class that changes the color on hover. Here's the working fiddle: http://jsfiddle.net/KVmCt/6/

    jQuery looks like this:

    $("div").hover(
    function(){
    $(this).addClass("blue");
     }
    ,
    function(){
    $(this).removeClass("blue");
    });
    

提交回复
热议问题