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

后端 未结 6 511
梦谈多话
梦谈多话 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条回答
  •  猫巷女王i
    2020-11-30 05:10

    Use JQuery Hover to add/remove class or style on Hover:

    $( "mah div" ).hover(
      function() {
        $( this ).css("background-color","red");
      }, function() {
        $( this ).css("background-color",""); //to remove property set it to ''
      }
    );
    

提交回复
热议问题