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

121
Vistas
Press enter on an image and it plays a sound?

I have a tabbable image that I want to play a sound if it is tabbed to and enter is pressed. It's not a button for a form or anything, just an image. How can this be done?

 <img src="/images/butt.gif" onclick="fartSound();" tabindex="0">

I already have Javascript where a sound is played when clicked, but I would really love it if I could also have the sound played when it is tabbed to and enter is pressed.

function fartSound(){
  var sound = new Audio('/audio/fart.mp3');
  sound.play();
};

Any ideas? Thanks!

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

0

You can listen to the focus event with javascript.

Something like element.addEventListener('focus', fartSound);

Working demo:

Just click on the white space and hit tab, you will see the console log.

function fartSound(){
  console.log("Prrr");
  var sound = new Audio('/audio/fart.mp3');
  sound.play();
};


const funnyPic = document.getElementById('funnyPic');

funnyPic.addEventListener('focus', fartSound);
 <img src="/images/butt.gif" tabindex="0" id="funnyPic">

about 4 years ago · Juan Pablo Isaza Denunciar

0

Add addEventListeners for pressing(keydown) on 'enter'. and add onFocus event in HTML to call the function on click or tabbed

function fartSound(){
  console.log('clicked');
  var sound = new Audio('/audio/fart.mp3');
  sound.play();
};


const element = document.getElementById('element');

element.addEventListener('keydown', function(e) {
    //Enter key value is 13
    if(e.which == 13) {
       fartSound();
    }
});
 <img src="/images/butt.gif" onfocus="fartSound()" tabindex="0" id="element">

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