Home > Software design >  Why does using the ".play" action not play this video?
Why does using the ".play" action not play this video?

Time:01-03

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

CodePudding user response:

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

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

More on play()

CodePudding user response:

<img src="overlay.png" onclick="playit();">

Remove semicolon ; when palyit function call with onclick event like this onclick="playit()"

  • Related