Call twice timeupdate

There is a problem for calling twice timeupdate. My code is:

$("video").on(
    "timeupdate",
    function(event){
        alert('work');
    }
);

it works, but if I do this:

$('#video').html( $('#newVideo').html());

the previous code does not work.

I try the following way does not work either:

  • <video id="video">

  • `$ (document) .on (" timeupdate ", 'video',

    $ (document) .delegate ('video',

    $ ("video"). To tie (

    $ ("video") .live (`

+1
source share
2 answers

My decision:

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

you must enable the video tag again after the changes and before the call function for ex. thus:

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

.on() , , , - .

// 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
+1

Source: https://habr.com/ru/post/1016495/


All Articles