I have a video
element and a script that attaches an onplay
handler to the video via jQuery:
<video id="vid" />
<!-- ... -->
<script type="text/javascript">
$('#vid').on('play', function () {
$(this).addClass('playing');
});
</script>
According to this answer, users might be able to interact with the video player before the script is loaded. But I need to make sure that my event handler is attached before the onplay
event can be fired.
To test this, I added a script right after the video
that calls play()
. The handler is run on all major browsers except WebKit, which doesn't play the video at all. Even wrapping the jQuery statement in a $().ready()
function still lets the handler be attached before onplay
.
Is it guaranteed that my script will never miss any events from the video in HTML5? Does the same apply to all DOM events? What if I add async
to the script?