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

236
Views
How to pass variables to jQuery click/onclick function without triggering function?

My card game triggers the click event for all cards once the DOM is loaded. My code originally looked like

$.each(cardArray, function(i,value){
 var activeCard = $('<div class="cardContainer" title="'+cardArray[i]['name']+'" >'+cardArray[i]['damage']+'</div>');
 activeCard.click(doStuff(i,activeCard));
}

but after finding some other helpful responses to the same issue I discovered this was due to the () resulting in the function execution so my new call should look like

$.each(cardArray, function(i,value){
 var activeCard = $('<div class="cardContainer" title="'+cardArray[i]['name']+'" >'+cardArray[i]['damage']+'</div>');
 activeCard.click(doStuff);
}

Unfortunately this means I'm left without being able to pass variables I need. What are possible solutions or best practices here?

about 4 years ago · Juan Pablo Isaza
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!