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

173
Views
jQuery agrega evento a cada hijo de Node

el nodo <'ul'> que recibí de forma asíncrona contiene entradas <'li'>. Necesito agregar un evento a cada 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>

Según tengo entendido, necesito usar algo como:

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

Y probablemente necesito .each .
¿Puede describir cómo utilizar esta función en este caso concreto?

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

0

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

about 4 years ago · Juan Pablo Isaza Report

0

Puede adjuntar el controlador de eventos solo al elemento principal, el .parent , y el evento solo necesita burbujear desde el li al ul en el que se hizo clic:

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

Manifestación:

 $('.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 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!