Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get the :hover css style of an anchor with jQuery?

How can i get the :hover in css stylesheet on the fly with jquery?

stupid example:

a.foo {
    color: red;
    font-size: 11px;
}

a.foo:hover {
    color: blue;
    font-size: 12px; 
}

how to retrieve that color and font-size before that mouse will go over the anchor?

like image 526
apelliciari Avatar asked Mar 17 '09 13:03

apelliciari


2 Answers

If you really need to, you can access this information throught the document.styleSheet property. An example is available here: http://jsfiddle.net/Xm2zU/1/

Please note that IE would need its own code to do this as it uses ".rules" rather than ".cssRules" etc.

like image 184
Bjorn Inge Avatar answered Sep 28 '22 05:09

Bjorn Inge


Take a look at Extra selectors for jQuery.

Also, you can use the hover event, depending on what you want to achieve. See: jQuery hover and class selector.

like image 21
Can Berk Güder Avatar answered Sep 28 '22 07:09

Can Berk Güder