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

52
Views
Jquery UI haga clic en el enlace

Tengo algunos enlaces dentro de div. Si los usuarios hacen clic en cualquier área del div, debería hacer algo. Pero debería hacer algo más si los usuarios hacen clic en un enlace.

¿Cómo puedo saber si el clic es en un enlace? Por cierto, no puedo usar la función onclick() en el enlace.

 <html> <head> <script src="https://code.jquery.com/jquery-3.5.0.js"></script> </head> <body> <div class="mydiv"> do something<br /> <a href="#"> do other</a><br /> do something<br /> </div> <script> $(document).ready(function () { $('.mydiv').click(function () { var ahref = $(this).attr('href'); if (ahref == null) { alert('do something'); } else { alert('do other'); } }); }); </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar la propiedad nodeName para verificar si el elemento en el que se hizo clic tiene a etiqueta o no.

 <html> <head> <script src="https://code.jquery.com/jquery-3.5.0.js"></script> </head> <body> <div class="mydiv"> do something<br /> <a href="#"> do other</a><br /> do something<br /> </div> <script> $(document).ready(function () { $('.mydiv').click(function (e) { if (e.target.nodeName == 'A') { alert('do other'); } else { alert('do something'); } }); }); </script> </body> </html>

https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName

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!