W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2007

Re: How is the hover pseudo-class translated into the DOM?

From: Yansky <thegooddale@gmail.com>
Date: Tue, 27 Mar 2007 01:59:48 +1000
Message-ID: <4607EDF4.9080406@gmail.com>
To: www-dom@w3.org

Thanks for your help so far. :)

I'm still having some trouble though getting the hover colour of an <a> 
element. This is what I've tried:

var theLink = document.getElementsByTagName('a')[3];
document.defaultView.getComputedStyle(theLink, 
'hover').getPropertyValue('color');

but it only returns the regular colour, not the hover colour. Am I doing 
something wrong?

Joćo Eiras wrote:
> It's the other way around. pseudo-element are not visible to the DOM.
> pseudo-classes styles are applied on the fly, and getComputedStyle
> will retrieve the styles which are applied to the element when
> getComputedStyle is called.
>
> 2007/3/26, Yansky <thegooddale@gmail.com>:
>>
>> But doesn't getComputedStyle(...) only work for pseudo-elements; not
>> pseudo-classes?
>>
>> Joćo Eiras wrote:
>> > Na , Yansky <thegooddale@gmail.com> escreveu:
>> >
>> >>
>> >> Hi, I was wondering about the :hover pseudo-class in style rules and
>> >> how that translates into the DOM. Is it translated into the browser
>> >> as a Javascript-type mouseover event? Would it be possible to read
>> >> the style rules set to the hover pseudo-class via onmouseover?
>> >>
>> >> Cheers,
>> >> Yansky.
>> >
>> > mouseover/mouseout are fired if the mouse is moved either over a child
>> > of the target or another node in the document tree, so you need to
>> > check if the element to where the mouse is going is a descendant of
>> > the previous node. Like, onmouseover, check that target is a
>> > descendant of relatedTarget.
>> > Then, since :hover styles are applied dynamically, without any script
>> > intervention, you can read the computed styles for some element in the
>> > DOM, using getComputedStyle(...)
>> >
>> >
>> >
>>
>>
>
Received on Monday, 26 March 2007 16:00:02 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:58 GMT