I have a jQuery script where somebody can click a button to add this item to their favorites. Now, the problem is I want to add this button several times on the page - the exact same button with the same code. When I click one of the buttons, the first one gets updated but the others don't. Is there any way to update ALL the matching IDs? In other words, run this action for all matching cases on the page, except for the first one?
The code is like this:
$(document).on('click','#add-to-list',function (e) {
e.preventDefault();
var id = $(this).data("id");
$.ajax({
url: "http://xxx.xxx.xxx.xxx/add_to_list?id=" + id,
type: "GET",
dataType: 'json',
success: function(json) {
if(json.valid == 1) {
$("#list-button").hide();
$("#list-response").html('Added to Favorites');
$("#list-response").show();
}
},
timeout: 10000
});
});
And then on the page obviously I have multiple instances of
<div id="list-button">
(button here)
</div>
<div id="list-response">
(initially hidden)
</div>