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

后端 未结 6 512
梦谈多话
梦谈多话 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 04:59

    Well, you can't add styling using pseudo selectors like :hover, :after, :nth-child, or anything like that using jQuery.

    If you want to add a CSS rule like that you have to create a ')

    If you want to read more on adding CSS with javascript you can check out one of David Walsh's Blog posts.

提交回复
热议问题