html - Auto-play an HTML5 video on Dom Load using jQuery -


i'm trying play video dom has loaded using jquery. code:

html

<video id="video" width="420">   <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">   <source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">   <p>your browser not support html5 video.</p> </video> 

js (script.js)

$(document).ready(function() {   $(#video).play(); }); 

when dom loads video not play, going wrong? in advance.

the jquery selector $("#video") returns jquery object. since play() function of dom element, must dom element with:

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

before using .play() method:

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

edit: can use html5 selected tags in case jquery fall back. note autoplay tag.

<video controls="controls" autoplay="autoplay" loop="loop" width="233" height="147" poster="//www.cdn.com//video.png" preload="auto" title="video">     <source src="//www.cdn.com/video.mp4" type="video/mp4"/>     <source src="//www.cdn.com/video.ogv" type="video/ogv"/>     <source src="//www.cdn.com/video.webm" type="video/webm"/> </video> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -