Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Why is the display value on my video tag not updating as expected

For an upcomming project, I'm starting to experiment a bit with html5 video. I wrote a small class to manage video's.

const videoLayer = document.getElementById( "videoLayer" );

class videoPlayer {
    constructor( id, source ){
        this.id = id;
        this.source = source;
        videoLayer.innerHTML +=  
            `<video id="${ this.id }">
                <source src="${ this.source }" type="video/mp4">
            </video>`;
        this.element = document.getElementById( this.id );
        this.element.onended = () => {
            this.stop();
        }
        this.hide();
    }

    show(){
        this.element.style.display = "inline";
    }

    hide(){
        this.element.style.display = "none";
    }

    goToStart(){
        this.element.currentTime = 0;
    }

    play(){
        this.show();
        this.element.play();
    }

    pause(){
        this.element.pause();
    }

    stop(){
        this.pause();
        this.hide();
        this.goToStart();
    }

    toggle(){
        this.show();
        this.element.paused ? this.element.play() : this.element.pause();
    }
}

With only one instance, it all works just fine. But with multiple instances, only the last instance is working. If I use .play() on the first instance, only the audio starts playing. If I look at "inspect element" I can see that the display property keep showing "none". The weird thing is, if I add the following lines to the console, everything works fine.

const test = document.getElementById( theRightId );
test.style.display = "inline";
test.play();

If I add the line beneath to the show function, it returns the right element in the console. However, there it states that the display value is "inline".

console.log( this.element );

So I suspect that something is messing with the display value after execution.

And lastly, if I change the order of the instances, they all work as long as they are the last created instance.

Any ideas?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!