Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda