Auto-play an HTML5 video on Dom Load using jQuery

后端 未结 3 652
野的像风
野的像风 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:44

    $('video#video').each( (i,e) => e.play() );
    

    As Justin McDonald noted, the play() method exists on the Video DOM Node itself, so you first have to resolve the jQuery Object to the specific Node. However, his solution will throw an error if the element with id="video" does not exist or is not a video Node.

提交回复
热议问题