I have a series of buttons that I'm appending a data ID to. I'm then trying to get the value of that button when it's clicked to push it into an array that eventually I'll read back out for applying some cookie values to.
I've piecemealed some bits together from other code examples. I feel that I'm really close, but I'm just not sure how to pull out the data ID to insert it into the array:
var z = [];
jQuery(document).ready(function($) {
$(".btn").each(function(i) {
i = i + 1;
$(this).attr('data-id', ("btn_" + i));
});
$('.btn').each(function() {
var btnData = $(this).data('id');
$(this).click(function(e) {
z.push($(btnData).val());
console.log(z);
});
});
});
Not sure what part I'm missing overall. Think it's something in the z.push($(btnData).val());.
var btnData = $(this).data('id');And modified thisz.push($(btnData).val());toz.push($(this).data('id'))