I have a bunch of divs that when they are clicked I want to update some data that is associated with it. I have a click event registered with the div but I can't figure out how to pass the data into the click event handler along with it. I've looked at quite a few other similar SO questions but haven't found a working solution yet.
I want to basically be able to click a box and pass the number along with it:
var numbers = ['one', 'two', 'three', 'four'];
var container = document.getElementById('container');
for (var i = 0; i < numbers.length; i++){
var checkbox = document.createElement('div');
checkbox.setAttribute('class','checkBtn');
var save = function(){
console.log(numbers[i]);
}
$(checkbox).click(function(){
save();
});
container.appendChild(checkbox);
}