Skip to content

Instantly share code, notes, and snippets.

@DoubleMarv
Created April 29, 2020 11:35
Show Gist options
  • Save DoubleMarv/23362df4c3dfc0c8855023d667f0ca85 to your computer and use it in GitHub Desktop.
Save DoubleMarv/23362df4c3dfc0c8855023d667f0ca85 to your computer and use it in GitHub Desktop.
dynamically add mp4 video from data-src to src
//html
<video muted loop data-src="vid/packaging.mp4" id="internalbannervideo">
<source src="" type="video/mp4">
</video>
//js
function swapVidSource() {
var vidplayer = document.getElementById("internalbannervideo");
var thedata = vidplayer.getAttribute('data-src');
vidplayer.src = thedata;
vidplayer.play();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment