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

202
Views
Add new value to variable on every new function run without losing the old ones (jQuery)

Is there a way to add a variable to the existing ones at every new function run, without losing the old ones?

Function example:

// this div value gets changes by an other click event
<div class="data">204</div>

$(".button").on('click', function(){
  var data = $('.data').text();
  var dataCollection = data + data; // + new data, the old ones should not be deleted
  console.log(dataCollection); // here I wanna see a list of all data
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Do not redefine the variable each time. What you are doing would make more sense as an array.

var dataCollection = [];
$(".button").on('click', function(){
  var data = $('.data').text();
  dataCollection.push(data)
  console.log(dataCollection);
});
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!