Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by apires for Dynamically loading and autoplaying HTML5 video

Use .play()after adding it's src.

jQuery(document).ready(function($) {"use strict";  $("video").each(function() {    var $source = $(this).find('source');    var src = $source.attr('data-src');    $source.removeAttr('data-src');    $source.attr('src', src);    $source.detach().appendTo($(this))    $(this).get(0).play();  });});
video {  width: 420px;  height: 230px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><video loop="loop" poster="http://placehold.it/420x230"><source type="video/mp4" data-src="http://techslides.com/demos/sample-videos/small.mp4"></video>

Viewing latest article 1
Browse Latest Browse All 2

Trending Articles