- From: Olli Pettay <Olli.Pettay@helsinki.fi>
- Date: Sun, 15 May 2011 03:17:21 +0300
On 05/15/2011 01:24 AM, Ojan Vafai wrote:
>
> It's unfortunate that you need to use an inline event handler instead of one
> registered via addEventListener to avoid the race condition. Exposing
> something to the platform like jquery's live event handlers (
> http://api.jquery.com/live/) could mitigate this problem in practice, e.g.
> it would be just as easy or easier to register the event handler before the
> element is created.
There is no need to use inline event handler.
One can always add capturing listener to window for example.
window.addEventListener("canplay",
function(e) {
if (e.target == document.querySelector('video') {
// Do something.
}
}
, true);
And just do that before the <video> element occurs in the page.
That is simple, IMHO.
jQuery cannot do anything more than that. So if you add the event
listener using jQuery after the <video> element, "canplay" may have
already fired.
(I wonder why the "Firing a simple event named e" defaults to
non-bubbling. It makes many things harder than they should be.)
-Olli
>
> Ojan
>
Received on Saturday, 14 May 2011 17:17:21 UTC