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

278
Views
event.preventDefault() en keydown no funciona

Intentando capturar las pulsaciones de teclas en los menús del panel de pestañas de Bootstrap, pero simplemente aparece ignorando el preventDefault () colocado en el controlador de teclas de las pestañas.

 document.onkeydown = function(e) { console.log("document catched the keydown event"); }; $('body > div > ul > li > a').on("keydown",function (e) { console.log("handled by the child - stop bubbling please"); e.preventDefault(); });

Ejemplo: http://www.bootply.com/xUlN0dLRaV

que me estoy perdiendo aqui ?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Prueba e.stopPropagation()

e.stopPropagation() evita que el evento se expanda en el árbol DOM , lo que evita que se notifique el evento a los controladores principales.

 $('body > div > ul > li > a').on("keydown",function (e) { console.log("handled by the child - stop bubbling please"); e.preventDefault(); e.stopPropagation(); });

¿Diferencia?

¿Cuál es la diferencia entre event.stopPropagation y event.preventDefault?

about 4 years ago · Santiago Trujillo Report

0

Además e.preventDefault , también debe usar e.stopPropagation() para evitar que el evento aumente. En su caso, también puede devolver false desde el controlador de eventos que hace ambas cosas:

 $('body > div > ul > li > a').on("keydown",function (e) { console.log("handled by the child - stop bubbling please"); return false; });
about 4 years ago · Santiago Trujillo 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!