Reputation: 5002
I have a list that page load, loads items. and when click checkbox in page load items with json.
$('.content-items:checkbox').on('change',
function () {
$.get(newUrl, function (data) {
$("#ProductsPartialView").empty();
$("#ProductsPartialView").append(data);
$('#loadingModal').modal('hide');
}).fail(function (xhr, err) {
alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
alert("responseText: " + xhr.responseText);
});
});
when click items element run a function.
$('.compare-items:checkbox').on('change',
function() {
$('#loadingModal').modal('show');
var value = $(this).data('id');
$.getJSON("/store/AddToCompare", {
id: value, add: true
}, function (result) {
$(".compare-footer").show();
$(".compare-count").html(result);
$('#loadingModal').modal('hide');
});
}
});
when load items in page load, fire this jquery, but when load items with json in first code, don't fire second function.
Upvotes: 0
Views: 37
Reputation: 5322
for that you need $(document).on(event,selector, cb{});
when you want to do action on dynamic generated data
$(document).on('change','.compare-items:checkbox',
function() {...
Upvotes: 2