简体   繁体   English

使用jQuery设置链接悬停属性

[英]Setting link hover property with jQuery

I want to change the background color of a link with jQuery, the orginal CSS for the link is 我想使用jQuery更改链接的背景颜色,该链接的原始CSS是

#container ul li:hover ul li a{
    background: #FF0000
}

I'm trying the following jQuery code, but it does not seem to work. 我正在尝试以下jQuery代码,但它似乎不起作用。

jQuery('#container ul li:hover ul li a').css('background', '#FF0000');

I can set the css for the normal links, but its only causing problem with the link hover. 我可以为普通链接设置css,但这只会导致链接悬停出现问题。

try this: 尝试这个:

jQuery('#container ul li ul li a').hover(function(){
   $(this).css('background', '#FF0000');
})

or this : 或这个 :

jQuery('#container ul li').hover(function(){
   $(this).find("ul li a").css('background', '#FF0000');
})

You could try it with the jquery hover function. 您可以尝试使用jquery悬停功能。 http://api.jquery.com/hover/ And re-set the color. http://api.jquery.com/hover/并重新设置颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM