Auto-play an HTML5 video on Dom Load using jQuery

后端 未结 3 651
野的像风
野的像风 2021-01-18 07:38

I\'m trying to play a video as soon as the dom has loaded using jQuery. This is my code:

HTML

3条回答
  •  醉梦人生
    2021-01-18 07:53

    The jQuery selector $("#video") returns a jQuery object. Since play() is a function of the DOM element, you must get the DOM element with:

    $("#video").get(0);
    

    before using .play() method:

    $("#video").get(0).play();
    

    Edit: You can also use HTML5 selected tags in case jQuery fall back. Note the autoplay tag.

    
    

提交回复
热议问题