5

If I define the up and over states of a button like this:

.button {color:red;}
.button:hover {color:blue;}

How can I get all the hover state styles for an element using JQuery?

Something like $(".button:hover").css('color');...

2
  • 1
    forum.jquery.com/topic/… Commented Apr 30, 2010 at 22:51
  • thanks, yeah it looks like it is not possible. when it is, let us know :) Commented Apr 30, 2010 at 23:45

1 Answer 1

1

This isn't possible directly, at least not without hovering. The closest you can get is:

$('.button').mouseenter(function() {
  alert($(this).css('color'));
});

But...this requires hovering over the element, which by your question doesn't sound like the goal. Because of the way hovers are done, there was never any reason to expose this information in javascript, the browser css/rendering engine handles all of it...since this is maybe the second time I've seen this asked in years, it's just one of those rarely-used so never-added things, like every other language/platform has a thousand examples of.

Sorry the answer sucks, but "it doesn't do that" is the answer for everything at some point, but will probably remain that way in this case.

Sign up to request clarification or add additional context in comments.

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.