views:

64

answers:

1

I was looking at google.com source and saw:
<!doctype html><html onmousemove="google&&google.fade&&google.fade(event)">

I did not know the HTML tag could accept event listeners. What is the difference of placing the event listener on the HTML tag versus the BODY tag? Is there any difference in the event bubbling?

+1  A: 

I saw this a couple of days ago and didn't give it much thought. But one reason could be "performance" as it always is with Google :)

For an extremely slow client, <html> will be parsed first thing and the onmousemove handler will be ready to fire if the user moves the mouse. If there is too much content inside <head>, this may be more preferable as the onclick on <body> may take a little while to register as all that head content has to be downloaded and parsed first.

Actually that is already happening, there is approximately 2KB of content before <body> appears.

Anurag
Should I move all of my body event listeners to the HTML tag?
Christopher Altman
Except `onload`. That, I believe will not be sent to html at all.
Anurag
Actually that is wrong, not all events apply to the html element. Just like change would have no effect on body, it won't work on html either. And load doesn't work based on local tests, but I can't find any supporting documentation.
Anurag