samscoolwebsite.com
samscoolwebsite.com

Reputation: 3

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

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

Upvotes: 0

Views: 60

Answers (2)

Asad Saeed
Asad Saeed

Reputation: 11

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

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

Upvotes: 1

Rico
Rico

Reputation: 2057

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

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

More on play()

Upvotes: 1

Related Questions