- From: Simon Pieters <simonp@opera.com>
- Date: Sun, 25 Oct 2009 22:14:12 +0200
On Fri, 23 Oct 2009 17:16:13 +0300, Markus Ernst <derernst at gmx.ch> wrote: > In 6.5.6.2 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: > > <body> > <p onload="dosomething(this)">Text</p> > <p onload="dosomethingelse(this)">Text</p> > </body> > > <body onload="dosomething(document.getElementById('foo')); > dosomethingelse(document.getElementById('bar'))"> > <p id="foo">Text</p> > <p id="bar">Text</p> > </body> > > 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. http://www.whatwg.org/specs/web-apps/current-work/multipage/section-index.html#events-0 (and the tables referenced from there) is useful for finding out which events are fired where. HTH, -- Simon Pieters Opera Software
Received on Sunday, 25 October 2009 13:14:12 UTC