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

94
Views
elemento onclick en clase nunca llamado

Tengo una clase sencilla.

El problema que tengo es que mi función onClick nunca se llama al hacer clic en el elemento div.

 class card { constructor(parent, element) { this.parent = parent; this.element = element; this.element.on({ 'click': $.proxy(this.onClick, this) }); } onClick() { console.log("onclick"); } } class cards { constructor() { this.element = $(".cards"); this.cards = []; this.element.children(".card").each((obj) => { this.cards.push(new card(this, $(obj))); }); } } var my_a = new cards();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

each(index, element) pasa dos parámetros a la devolución de llamada. El primero es el índice, el segundo es el elemento. Está envolviendo el índice, no el elemento dom.

cada documento

 class card { constructor(parent, element) { this.parent = parent; this.element = element; this.element.on({ 'click': $.proxy(this.onClick, this) }); } onClick() { console.log("onclick"); } } class cards { constructor() { this.element = $(".cards"); this.cards = []; this.element.children(".card").each((obj, el) => { console.log(el); this.cards.push(new card(this, $(el))); }); } } var my_a = new cards();
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <div class="cards"> one asdf <div class="card"> card 1 asdf </div> <div class="card"> card 2 asdf </div> </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!