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

182
Vistas
PreventDefault() with named function and function parameter

I'm trying to add an e.preventDefault() call to my event listener. My function call "voteNoClick" needs to pass a parameter ("direction"). How do I pass both the direction parameter and the event object into the function so I can then add e.preventDefault() within the function? When I try to add the event "e" as a parameter in addition to "direction" it seems to think e is an ordinary parameter.

Thanks in advance!

document.getElementById('voteButtonNoID').addEventListener('click', voteNoClick(direction));
function voteNoClick(direction) {
       // I want to add e.preventDefault() here
        document.getElementById("voteMessageID").innerHTML = "Waiting for the votes to be tallied...";
        voteResults('no',direction);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Hello you can try this

document.getElementById('voteButtonNoID').addEventListener('click', (e) => voteNoClick(e, direction));

function voteNoClick(e, direction) {
 e.preventDefault();
 document.getElementById("voteMessageID").innerHTML = "Waiting for the votes to be tallied...";
 voteResults('no',direction);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

return another function inside it and you can access event like this.

function voteNoClick(direction) {
    return function(event){
    // your code ...
        event.preventDefault()
        document.getElementById("voteMessageID").innerHTML = "Waiting for the votes to be tallied...";
        voteResults('no',direction);
    }
}
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