Search code examples
javascriptjqueryhtml-tablekeyup

Not work jQuery for for input value


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.


Solution

  • As you are creating the element dynamically, you should delegate the event:

    $(document).on('keyup', 'input.count', function(e){
        alert('test');
    });