0

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)?

1
  • You can use hover. See my answer below. Commented Mar 24, 2011 at 19:48

8 Answers 8

3

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", "");
});
Sign up to request clarification or add additional context in comments.

Comments

1

yes use .hover()

Comments

1

Edited:

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

Comments

0

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

Comments

0

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

Comments

0

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

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

Comments

0

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(){})

Comments

0

You're selecting the tag while it's in a psudo-state of being hovered (":hover" is a pseudo-class), so you would need to hover over your tag and run that script at the same time in order to successfully select the element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.