How to define the css :hover state in a jQuery selector?

后端 未结 6 514
梦谈多话
梦谈多话 2020-11-30 04:10

I need to define a div\'s background color on :hover with jQuery, but the following doesn\'t seem to work:

$(\".myclass:hover div\").css(\"background-color\         


        
6条回答
  •  伪装坚强ぢ
    2020-11-30 04:59

    You can try this:

    $(".myclass").mouseover(function() {
        $(this).find(" > div").css("background-color","red");
    }).mouseout(function() {
        $(this).find(" > div").css("background-color","transparent");
    });
    

    DEMO

提交回复
热议问题