Reputation: 327
Main code:
var clone = div.clone();
clone.attr('id', sabad_kala_id);
$('.content').append(clone);
$('div#'+sabad_kala_id).replaceWith('<tr id='+sabad_kala_id+'><td width="50"><a class="del_kala" id='+sabad_kala_id+'><img src="images/delete.png" alt="delete" /></a></td><td width="50">1.</td><td width="388">'+title+'</td><td width="80" clas="mm"><input class="count" type="text" value='+count+' /></td><td width="100">'+price+' $</td><td width="120">'+price_count+' $</td></tr>');
and this code run perfect
after append and replace, user can edit input.count
in table and below code have run :
('input.count').keyup(function(e){
alert(test);
});
but this code does not work.
Upvotes: 2
Views: 133
Reputation: 233
The code doesn't work because the handler keyup is executed when the page loads and won't respond to any objects added later. Use to fix your code.$(".count").live('keyup', function(){})
Correction: use $(document).on("keyup", ".count", null, function(){ // code here})
since jQuery 1.7 (see http://api.jquery.com/live/)
Upvotes: -1
Reputation: 144709
As you are creating the element dynamically, you should delegate the event:
$(document).on('keyup', 'input.count', function(e){
alert('test');
});
Upvotes: 6