1
votes

I am getting an error Uncaught TypeError: Object [object Object] has no method 'addEventlistner' when adding this code, i can't get my head around it :(

$('video').addEventlistner('timeupdate', function(event) {
    var current = Math.round(event.target.currentTime * 1000);
    var total = Math.round(event.target.duration * 1000);
    $('temps_total').empty().appendText(total);
    $('temps_courant').empty().appendText(current)
    $('temps_restant').empty().appendText(total - current);
    });
3
Note that the native function is spelled with "listener" (and capitalized). - pimvdb

3 Answers

4
votes

Because $('video') returns a jquery object.

Here is what you can do:

$('video')[0].addEventListener('timeupdate', function(event) {
2
votes

You would use addEventListener not addEventlistner but neither are jQuery methods.

Read this http://api.jquery.com/on/

$('video').on('timeupdate', function(event) {
    var current = Math.round(event.target.currentTime * 1000);
    var total = Math.round(event.target.duration * 1000);
    $('temps_total').empty().appendText(total);
    $('temps_courant').empty().appendText(current)
    $('temps_restant').empty().appendText(total - current);
});
1
votes

jQuery objects do not have an addEventListener method.
Instead, you should call .bind().