What happens first, CSS or JS events?

If, for example, you apply the CSS hover effect to an element and also place a JSE mouse event on it, which one will happen first? Is there any difference in this? Can you somehow control it? Is it possible to make them execute in a specific order?

+4
source share
2 answers

which one will be the first?

Please note that there is no such thing as a “CSS event”. However, the behavior is undefined; You can consider changing CSS and JS events at the same time. Relevant specifications CSS 4 Selectors , DOM 3 Events, and HTML 5 indicate similarities between hoverand mouseenter, but do not indicate order. The order of mouse events is specified , but does not apply to pseudo-classes of custom CSS actions.

Are there any deviations from this?

Yes, browsers can implement it anyway. They can change the layout and redraw the page before they trigger JS events, or they cannot. However, this does not really matter.

Is it possible to make them execute in a specific order?

, CSS JS. , (, getComputedStyle(this)) CSS, - . DOM-?.

http://jsfiddle.net/n4Z8H/. (rgb(0, 0, 255), :hover), IE, , .

+3

, , . . , / , CSS JavaScript, , .

, , , , - .

0

Source: https://habr.com/ru/post/1525698/


All Articles