简体   繁体   中英

Selector CSS JQuery

Is it normal that

$("#foo a:hover")

does not select anything?

I can't use hover cause I need this selector to do that :

 $("#foo a:hover").css("color", mycolor);

So I wonder if something like

 $("#foo").css("a:hover color", mycolor);

exist?

Et What about visited (pseudo class)?

Yes, that is completely normal. jQuery doesn't have a :hover pseudo class.

You can use the hover method to bind two event handlers that add and remove the style:

$("#foo a").hover(function(){
  $(this).css("color", mycolor);
},function(){
  $(this).css("color", "");
});

是的,使用.hover()

Edited:

$("#foo a").hover(function(){ 
   $(this).css('color','mycolor');
});

When nothing is currently hovered, yes. Something would need to concurrently be in the hover state.

Yes, refer to the jQuery selector documentation for a list of valid selectors.

Instead you should be using the jquery .hover() with $("#foo a")

http://api.jquery.com/hover/

Yes because that selector will have fired BEFORE you hover anything. For example, if you were to just do:

$('#foo')

And then later on in the script append() foo it will not select anything because it didn't exist.

If you DO want to do something on hover you can do .hover(function(){},function(){})

您在标记处于悬浮状态时选择标记(“:hover”是伪类),因此您需要将鼠标悬停在标记上并同时运行该脚本才能成功选择元素。

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