simonp at opera.com
Sun Oct 25 13:14:12 PDT 2009
On Fri, 23 Oct 2009 17:16:13 +0300, Markus Ernst <derernst at gmx.ch> wrote:
> In 220.127.116.11 of the spec I found, that the onload event handler is now
> available for every HTML element in HTML5, which I think is a great
> improvement. But there is something on the load event, that I think
> would be worth some words to clarify.
> According to 6.11.2 the load event is fired when the whole document is
> loaded; I did not find anything about element-specific load events. So I
> assume that element1.onload is triggered by the same event as
> element2.onload - the following two bodies would be equivalent:
> <p onload="dosomething(this)">Text</p>
> <p onload="dosomethingelse(this)">Text</p>
> <body onload="dosomething(document.getElementById('foo'));
> <p id="foo">Text</p>
> <p id="bar">Text</p>
> Is this assumption correct?
No. The first registers two listeners on two elements, and the second
registers one listener on the window. When the document loads, a load
event is fired on the window, but there's nothing that fires load events
on <p>, so for the first example to do anything you have to fire the event
yourself with script.
> Generally, the list of events that must be supported by all HTML
> elements looks somehow confusing to me, as there are some events that
> only apply to special types of elements, such as media players or forms
> resp. form elements. How are e.g. onpause or oninput supposed to work if
> applied to span or p elements?
Same as onload -- it just registers a listener. pause and input events
don't bubble and don't fire on span or p unless you do it yourself with
script. Maybe it doesn't make any sense to have <p onpause>, but it's
easier to implement (which in turn means less bugs and thus less headaches
for authors) to support all event handlers everywhere.
(and the tables referenced from there) is useful for finding out which
events are fired where.
More information about the whatwg