utdev
utdev

Reputation: 4102

Javascript onclick video object autostart true

How can I change a property of a source element / video object.

In my case I want to change the property autostart from false to true;

html:

    <video id="modul_1_video" controls preload="none">
        <source id="modul_1_source" src="../video.mp4" type="video/mp4" autostart="false">
    </video>

js: (I do not want to use jquery)

    modul_1.onclick = function() {
        console.log("click works");
        document.querySelector("#modul_1_video > source").autostart = true;
    }

but it does not seem to work.

Upvotes: 0

Views: 312

Answers (3)

Jyotirmay
Jyotirmay

Reputation: 1825

modul_1.onclick = function() {
  console.log("click works");           
  document.getElementById("#modul_1_video").setAttribute("autostart","true");
}

Upvotes: 0

Hari Krishna
Hari Krishna

Reputation: 67

set "autostart" attribute to true on click

document.getElementById('modul_1_source').setAttribute('autostart','true');

Upvotes: 0

Hoyen
Hoyen

Reputation: 2519

why don't you just use the play function?

modul_1.onclick = function() {
    console.log("click works");
    var video = document.getElementById("#modul_1_video");
    video.play();
}

Upvotes: 2

Related Questions