I am trying to insert an HTML5 <video> element through Javascript, but it fails to autoplay despite it being muted.
Background Context
I would like to transfer all of my gif assets over to an mp4 format. Likewise, I would like the HTML video to emulate a gif. It should include the following properties:
- Be muted
- Autoplays as soon as the webpage loads
- Loop indefinitely
- Plays in line
I am currently on Chrome 100.
What I've Tried
Relevant code is held within this codepen. I want to add the HTML video dynamically through javascript. However this fails to autoplay even though both autoplay and muted attributes are specified.
However, if I have the video element with the same attributes directly written in my HTML, the autoplay functionality works just fine.
How do I insert the video with JS and get it to autoplay?