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

204
Views
Obtenga el índice del elemento secundario en el que se ha hecho clic

Quiero adjuntar un detector de eventos a todas las clases de marcos img y obtengo qué elemento (por índice) dentro del padre se ha hecho clic:

 $('.img-frame').each((i, img) => { $(img).on('click', pictureClicked); }); function pictureClicked(e) { console.log(e.currentTarget) }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="three-image-container"> <img class="img-frame" src="blob:https://localhost:4000/daf31145-292d-462c-bc94-aad0610b2972"> <img class="img-frame" src="blob:https://localhost:4000/8e4a143e-f9f0-47ec-a361-4e571bb49d1a"> <img class="img-frame" src="blob:https://localhost:4000/c8236624-571d-4386-9225-e14e7fac9560"> </div>

Entonces, si se ha hecho clic en el primero, quiero 0 y ...

¿Cómo puedo hacer esto?

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

0

Desea delegar el evento para guardar en los controladores:

 $('.three-image-container').on('click', 'img', pictureClicked); function pictureClicked(e) { console.log($(e.target).index()) }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="three-image-container"> <img class="img-frame" src="blob:https://localhost:4000/daf31145-292d-462c-bc94-aad0610b2972"> <img class="img-frame" src="blob:https://localhost:4000/8e4a143e-f9f0-47ec-a361-4e571bb49d1a"> <img class="img-frame" src="blob:https://localhost:4000/c8236624-571d-4386-9225-e14e7fac9560"> </div>

about 4 years ago · Juan Pablo Isaza Report

0

Creo que debería ayudarte :)

 $('.img-frame').each((i, img) => { $(img).on('click', pictureClicked); }); function pictureClicked(e) { console.log($(e.currentTarget).index()) }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="three-image-container"> <img class="img-frame" src="blob:https://localhost:4000/daf31145-292d-462c-bc94-aad0610b2972"> <img class="img-frame" src="blob:https://localhost:4000/8e4a143e-f9f0-47ec-a361-4e571bb49d1a"> <img class="img-frame" src="blob:https://localhost:4000/c8236624-571d-4386-9225-e14e7fac9560"> </div>

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!