So, I have different elements like this:
<div data-action="change_status" data-date="2019-03-02" data-roomid="45" data-status="Close">Change status</div>
<div data-action="change_status" data-date="2019-03-02" data-roomid="46" data-status="Open">Change status</div>
<div data-action="change_status" data-date="2019-03-03" data-roomid="46" data-status="Close">Change status</div>
<div data-action="change_status" data-date="2019-03-03" data-roomid="47" data-status="Open">Change status</div>
For each click on element, I put the id of the element and some other informations in an array.
var arr = [];
$('[data-action="change_status"]').click(function(event) {
$(this).data('status', 'newValue');
arr.push({
current_status: $(this).data('status'),
current_date: $(this).data('date'),
current_roomid: $(this).data('roomid')
});
});
My problem is if the user click two times on the same element, it creates two rows in this array.
How can I check that an id already exists into the array and how can I update it with the last clicked value ?
Finally, I would like to pass this array in Ajax to a PHP page.
Thanks a lot.
inArray?