¿Hay alguna manera de agregar una variable a las existentes en cada ejecución de función nueva, sin perder las antiguas?
Ejemplo de función:
// 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 });No redefina la variable cada vez. Lo que estás haciendo tendría más sentido como una matriz.
var dataCollection = []; $(".button").on('click', function(){ var data = $('.data').text(); dataCollection.push(data) console.log(dataCollection); });