[SOLVED] Why does using the ".play" action not play this video?

Issue

I’m trying to make an image that, when clicked, will play a video, but when I click it the video doesn’t play. I’m using a chromium browser.

<img src="overlay.png" onclick="playit();">
<video id="video" loop>
     <source src="wheel.mp4" type="video/mp4">
</video>
        

<script>
     function playit() {
            document.getElementById("video").play;
     }
</script>

I’ve put a console.log() message in the same script, and it executes succesfully, but nothing occurs with the .play action

Solution

You need to call the play() method like so:

function playit() {
    document.getElementById("video").play();
}

More on play()

Answered By – Rico Hancock

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *