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

115
Vistas
Javascript to inject HTML with if statement

I'm trying to create a function that shows and hide a div through javascript injection. The function injects perfectly without the if (condition) like such: $("#video-container").load("include/video.html"); but fails to inject properly with the if statement. How does an if statement breaks something like this?

var show_video_feed_bool = false;
function show_video_feed() {
    if (show_video_feed_bool == false) {
        $("#video-container").load("include/video.html");
        show_video_feed_bool = true;
    }
    if (show_video_feed_bool) {
        document.getElementById("video-container").innerHTML = "";
        show_video_feed_bool = false;
    }
}

video.html

<div id="container">
    <video autoplay="true" id="videoElement">

    </video>
</div>
<script>
    var video = document.querySelector("#videoElement");

    if (navigator.mediaDevices.getUserMedia) {
        navigator.mediaDevices.getUserMedia({ video: true })
            .then(function (stream) {
                video.srcObject = stream;
            })
            .catch(function (err0r) {
                console.log("Something went wrong!");
            });
    }
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try:

show_video_feed_bool = false;
function show_video_feed() {
    if (!show_video_feed_bool) {
        $("#video-container").load("include/video.html");
    } else {
        document.getElementById("video-container").innerHTML = "";
    }
    show_video_feed_bool = !show_video_feed_bool;
}
about 4 years ago · Juan Pablo Isaza Denunciar
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