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

93
Views
¿Cómo puedo establecer algunos valores usando currentTarget con jQuery desde diferentes elementos HTML?

¿Alguien me puede dar una mano con esto?

Estoy tratando de obtener diferentes valores según el botón en el que se haga clic y asignarlo a una variable.

Un amigo me dijo que agregara los valores en una entrada para extraerlos más tarde mediante e.currentTarget , pero no pude hacerlo funcionar.

HTML:

 <div class="curso-contenedor"> <div class="curso"> <input id="precio" value='12000' hidden> <input id="cursoNombre" value='Web Developer' hidden> <form><button class="btn-curso web-developer" id="webDeveloper">Agregar</button></form> </div> <div class="curso"> <input id="precio" value='13000' hidden> <input id="cursoNombre" value='Marketing Digital' hidden> <form><button class="btn-curso marketing-Digital" id="marketinDigital">Agregar</button></form> </div> </div>

jQuery:

 $('.btn-curso').click(function(e){ let curso = {'precio': e.currentTarget('#precio'), 'curso': e.currentTarget('#cursoNombre')}; localStorage.setItem('datosCurso', JSON.stringify(curso)); e.preventDefault() });

Si alguien sabe cómo hacer esto, significaría mucho si me puede ayudar, ya que he estado atrapado con esto durante días intentando cosas diferentes.

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

0

Prueba esto: HTML

 <div class="curso-contenedor"> <div class="curso"> <input name="precio" value='12000' hidden> <input name="cursoNombre" value='Web Developer' hidden> <button class="btn-curso web-developer" id="webDeveloper">Agregar</button> </div> <div class="curso"> <input name="precio" value='13000' hidden> <input name="cursoNombre" value='Marketing Digital' hidden> <button class="btn-curso marketing-Digital" id="marketinDigital">Agregar</button> </div> </div>

JQuery:

 $('.curso-contenedor').on('click', '.curso', function(e){ let curso = { 'precio': $(e.currentTarget).find('input[name=precio]').val(), 'curso': $(e.currentTarget).find('input[name=cursoNombre]').val() }; localStorage.setItem('datosCurso', JSON.stringify(curso)); e.preventDefault() });

Debe agregar un detector de eventos delegado al elemento principal

Para más información: https://api.jquery.com/on/

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!