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

140
Vistas
JS Button to toggle youtube embedded video

So I made a toggle button with JS functionality inside elementor plugin. When button clicked for the first time, the embedded video will play. When clicked after that, it'll pause. And when clicked again, it'll play again. And so on. Here's the code I've written:


const vid1 = document.getElementsByClassName("eicon-play")[0];
let santanVid = 'pausing';

document.getElementById("santan-thumb").onclick = () => {
    
    if (santanVid = 'pausing') {
        santanVid = 'playing'
    } else if (santanVid = 'playing') {
        santanVid = 'pausing'
    }
    
    if (santanVid = 'pausing') {
        vid1.click();
        $('.elementor-video')[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*')
    } else if (santanVid = 'playing') {
        vid1.click()
        $('.elementor-video')[0].contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*')
    }
};

The problem is, it only worked once. The first time I load the page, click the button and the video will play. Click the button the second time, and the video stop. But if I clicked again, the video won't play

I've tried using 2 button and the code is working, the problem occurs when I'm using 1 button as a toggle, and I'm curious how to make it possible that way.

Thank you before!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In your if statements you are assigning values, not checking. To check use double or triple equal signs (==) or (===)

Example: if(santanVid === 'pausing')

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