The function window.getComputedStyle
is supposed to be able to get the computed style of pseudo classes like :hover, according to the documentation.
It's also explained as an answer in another question
But as the last comment says in that question, in fact it doesn't work at all, it just returns the normal style, not the :hover style. You can see for yourself in this jsfiddle. The alert returns the red color, not the green one.
The documentation on developer.mozilla.org also has an example, but that doesn't work either - see here.
In this question the answerer states in a comment that it won't work at all, but without giving an explanation.
Could it be that the stylesheet has to be fully rendered before the function returns the correct value? I've tried setting some delays, but nothing seems to work.
I've tried the latest Firefox, Chrome and IE browsers. Does anybody know why this function is not working as expected?