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

138
Views
Cómo manejar un onClick dentro de un elemento

Hay una lista de elementos como este:

 <a href={productPath} target={openInNewTab ? '_blank' : '_self'}> <figure> <img src={imageBaseUrl() + img} alt={product.title} /> </figure> {isFavorite ? ( <div className="remove-favorite" onClick={() => deleteCallBack(product.id)}> Delete </div> ) : null} </a>

pero cuando quiero hacer clic en el elemento div , pero se hace clic en mi href .

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puedes hacer stopPropagation() .

 {isFavorite ? <div className="remove-favorite" onClick={ (event) => { event.stopPropagation(); event.preventDefault(); deleteCallBack(product.id); } } > Delete </div> ) : null}

stopPropagation evita una mayor propagación del evento actual en las fases de captura y burbujeo.

preventDefault evita la acción predeterminada que realiza el navegador en ese evento.

about 4 years ago · Juan Pablo Isaza Report

0

Puedes usar event.stopPropagation()

 <div className="remove-favorite" onClick={(e) => { e.stopPropagation() deleteCallBack(product.id) }}> Delete </div>
about 4 years ago · Juan Pablo Isaza Report

0

Debe agregar en el evento onClick del enlace:

 onClick={(event) => { event.stopPropagation(); event.preventDefault(); }
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!