简体   繁体   中英

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

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

I'm trying the following jQuery code, but it does not seem to work.

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.

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. http://api.jquery.com/hover/ And re-set the color.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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