Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Cómo eliminar o deshabilitar evenListeners al hacer clic

Llegué a evenListeners uno para iniciar el temporizador y otro para detenerlo. ¿Es posible hacer que el de inicio funcione solo una vez y luego se deshabilite hasta que se haga clic en el botón de detener?

 startButton.addEventListener("click", startTimer); stopButton.addEventListener("click", function stopFunction() {})
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Sí, solo puede usar removeEventListener

 function startTimer() { // whatever code // Disable after use startButton.removeEventListern("click", startTimer); } startButton.addEventListener("click", startTimer); // Reset listener after stop button clicked stopButton.addEventListener("click", () => { startButton.removeEventListener("click", startTimer); startButton.addEventListener("click", startTimer); });

También se puede simplificar con taquigrafía:

 const disableBtn = () => startButton.removeEventListener("click", startTimer); const enableBtn = () => (disableBtn(), startButton.addEventListener("click", startTimer)); function startTimer() { // whatever code disableBtn(); } enableBtn(); stopButton.addEventListner("click", enableBtn);
about 4 years ago · Juan Pablo Isaza Report

0

al usar la línea a continuación, puede eliminar el oyente.

 startbutton.removeEventListener("click", startTimer);

y si desea manejarlo con otro botón, simplemente llame a una función al hacer clic.

 function stopFunction() { startbutton.removeEventListener("click", startTimer); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!