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

280
Vistas
How can I embed an event listener into a conditional in JavaScript?

What is the best syntax to express: "If I click this, this will happen but if it is not clicked, then another action will occur"? I want to keep CSS, HTML and JS separate, if possible.

I am trying to write code for "If I click this button, then the video will appear & play. But when it is not clicked, the video is hidden".

button = document.getElementByIdId('button')
video = document.getElementById('video')

button.addEventListener('click', function () {
(action here)
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Add an event listener to your play button where it calls videoElem.play()

HTML:

<video id='video'>
    <source src="your-video-source.mp4" type="video/mp4">
</video>

<button id='playVid'>Play</button>

Javascript:

document.getElementById('playVid').onclick = function () {
    document.getElementById('video').play();
};
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