jquery - Javascript adding new row with foreach function -
example: http://jsfiddle.net/k7jwlvt1/
$(function(){ var tbl = $("#table"); $("#addrowbtn").click(function(){ $("<tr><td>lorem ipsum</td><td>lorem ipsum</td><td>lorem ipsum</td><td>lorem ipsum</td><td><input type='checkbox' class='setbox'></td><td><button class='delrowbtn'>delete</button></td></tr>").appendto(tbl); }); $(document.body).delegate(".delrowbtn", "click", function(){ $(this).closest("tr").remove(); }); });
i adding new rows table have checkboxes @ end. meanwhile, have foreach loop check on these checkboxes execute ajax script that's trivial matter.
the foreach loop have works great if populate 1 row default (without clicking add row button). however, doesn't work new rows added subsequently. how have foreach loop detect new added rows after page load?
i've tried encapsulating foreach loop function , re-execute on each add row button click seems add ajax script in queue.
function setbox() { $(\".setbox\").each(function() { var ischecked = this.checked; $('.setbox').click(function() { $.ajax(blahblahblah}); } }); } }
any suggestions?
i think may , don't need use function setbox(). can try code.
$('body').on('click', '.setbox',function() { var ischecked = this.checked; alert(ischecked); //$.ajax(blahblahblah}); });
Comments
Post a Comment