JS and CSS are completely independent of one another. In other words, you cannot access the properties of a CSS class through JS, though you can access the CSS properties of an element, as JS acts on elements.
Solution
You can use some hackish solutions to solve this, but the best solution would probably be to create a "reverse extend" method in jQuery. In other words, you would have to write a method that does the opposite of .extend()
by taking two arrays and returning all of the properties in the second that are different from or non-existent in the first array. This is actually not as difficult as it sounds.
What you would do next is take each of the elements on the page and run your "reverse extend" method on them. You would have to pass the array returned by calling the .css()
method on the element when not hovering as your first parameter, and the array returned when calling the .css()
method on the element while hovering, as your second parameter.
If the resulting array is not empty, then the element does have a :hover
class defined (or a JS applied :hover
class). Here's the kicker: the resulting array will have all of the properties of the :hover
class!
A Note on Capturing Hover:
You can capture the hover by binding mousein
, mouseenter
, and hover
. I recommend using mousein
and mouseenter
and using a variable flag to indicate if the other was done. As they may run concurrently in some browsers, this may require a little extra funkiness with binding and unbinding the handlers, using the .on
and .off
methods, to prevent duplicate clones of the class. This implementation should give you support in all major browsers (IE6-10, Safari, Opera, Chrome, and Firefox).
Update: I was incorrect about being able to trigger the pseudo-hover state (sorry about that) - this is impossible through JS. However, you can use this solution for capturing the hover, and then clone the class' properties when it is first hovered. You can then add the hovered element to a jQuery array, which you will use to ensure that you do not look at the same element more than once (using .not
). The downside of this is that you will not be able to prevent cloning a :hover
pseudo-class more than once, if the same :hover
class is assigned to more than one element.
Let me know if you have any questions on this. Good luck! :)