Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
How can I set some values using currentTarget with jQuery from different HTML elements?

Can anyone give me a hand with this?

I am trying to obtain different values depending which button is clicked and assign it into a variable.

A friend told me to add the values in an input to later by extracted by e.currentTarget but I was unable to make it work.

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()
});

If anyone knows how to do this it would mean the world if you can help me since I have been trapped with this for days now trying different things.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this: 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()
        });

You should add delegate event listener to parent element

For more information: https://api.jquery.com/on/

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda