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

179
Vistas
jQuery add event to every child of Node

the node <'ul'> I received asynchronously contains <'li'> inputs. I need to add event to every li.

<ul class="parent">
  <li><input id="red" type="checkbox"></li>
  <li><input id="black" type="checkbox"></li>
  <li><input id="white" type="checkbox"></li>
</ul>

As I understand I need to use smth like:

$(document).on('change', '.parent' ....}) 

And probably I need .each.
Can you describe how to use this functionality in this certain case?

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

0

$('.parent').on('change', 'li input', function()})

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can attach the event handler to only parent element, the .parent, and the event only needs to bubble up from the clicked li to ul:

$('.parent').on('change', 'li > input:checkbox', function(){...});

Demo:

$('.parent').on('change', 'li > input:checkbox', function(){
  console.log($(this).attr('id'));
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="parent">
  <li><input id="red" type="checkbox"></li>
  <li><input id="black" type="checkbox"></li>
  <li><input id="white" type="checkbox"></li>
</ul>

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