Skip to content Skip to sidebar Skip to footer

No Return On$('input:checkbox').change(function() {?

I am testing a second solution that has been provided to me here, for checking and recording each check box that has been checked. First solution works like a charm but the second

Solution 1:

For dynamically create element we can not bind event directly do something like this or live function and this function is removed in 1.9 version so make sure what version of jquery you are using or many ways you can find out on jquery official site

$('body').on("change","input:checkbox",function() {
    alert('ah');
  var uLIndex = $('input:checkbox:checked').map(function() {
    returnthis.value;
  }).get();
  console.log(uLIndex);
});

Updated

Add a class to checkbox check

$('#tblListings').append(
    '<tr>' + '<td><inputclass="check"type="checkbox"name="updateListings[]"value=' + x + ' ></td>' + '<td>' + aLQuantities[x] + '</td>' + '<td>' + aLTitles[x] + '</td>' + '<td>' + aLPrices[x] + '</td>' + '<td>' + aLViews[x] + '</td>' + '<td>' + aLHearts[x] + '</td>' + '</tr>'
  );

And than bind event on all checkbox with class name check as below.

$('body').on("change",".check",function() {
    alert('ah');
  var uLIndex = $('input:checkbox:checked').map(function() {
    returnthis.value;
  }).get();
  console.log(uLIndex);
});

Post a Comment for "No Return On$('input:checkbox').change(function() {?"