Skip to content Skip to sidebar Skip to footer

Call Twice Timeupdate

have problem to call twice timeupdate. My code is: $('video').on( 'timeupdate', function(event){ alert('work'); } ); it work but if I do this: $('#video').htm

Solution 1:

Call .on() on an element higher up the heirarchy to ensure the event binding works for any element under it matching the selector - whether that element is currently existing or not.

// this will work for all <video> elements within the document object
$(document).on("timeupdate", 'video', function(event){
    alert('work');
});
// if possible change 'document' to something that is// closer up in the hierarchy to the video elements

Solution 2:

My solution is:

functioninitPlayer () {
    var player = $(document).find('video')[0];
    if (player) {
        player.addEventListener('timeupdate', function () {
            alert('work');
        }, false)
    }
}

must .find video tag again after changes and before call function for ex. in this way:

$( "#button" ).click(function() {  
    $('#video').html( $('#newVideo').html());
    initPlayer();
});

Post a Comment for "Call Twice Timeupdate"