javascript - Uncaught TypeError: Object [object Object] has no method 'addEventlistner' - Stack Overflow

I am getting an error Uncaught TypeError: Object [object Object] has no method 'addEventlistner�

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);
    });

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);
    });
Share Improve this question asked Nov 26, 2012 at 20:22 user1853799user1853799 111 silver badge4 bronze badges 1
  • Note that the native function is spelled with "listener" (and capitalized). – pimvdb Commented Nov 26, 2012 at 20:25
Add a ment  | 

3 Answers 3

Reset to default 4

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

Here is what you can do:

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

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

Read this http://api.jquery./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);
});

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745417055a4626796.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信