javascript - jquery .on function -
i've updated jquery script 1.9.1 , function stoped working .live()
.
i have got .on()
working doesnt remove item list, have update page see result.
generate html-code:
for (var = 0; < o.length; i++) { $('#listinserts').append('<div>' + o[i].text + '<a class="del" rel="'+ o[i].dataid +'" href="#">x</a></div>'); }
code before
$('.del').live('click', function() { delitem = $(this); var dataid = $(this).attr('rel'); $.post('dashboard/xhrdeletelisting', {'dataid': dataid}, function(o) { delitem.parent().remove(); }, 'json'); return false; });
code after
$(document).on('click','.del', function() { delitem = $(this); var dataid = $(this).attr('rel'); $.post('dashboard/xhrdeletelisting', {'dataid': dataid}, function(o) { delitem.parent().remove(); }, 'json'); return false; });
any idea going wrong?
with knowledge of html structure , knowing 'json' not appropriate, might try :
$('#listinserts').on('click','.del', function() { var delitem = $(this); var dataid = delitem.attr('rel'); $.post('dashboard/xhrdeletelisting', {'dataid': dataid}, function(o) { delitem.closest('div').remove(); }); return false; });
Comments
Post a Comment