user2388554
user2388554

Reputation:

jQuery setup keypress on datatables

i'm using datatables and for edit row i can insert input element on current row now, i want to setup enter keypress on input element but thar dont work in absolute inserted by jquery

jquery:

    $("#showCategories tbody").dblclick(function(event) {
            var nTds_showCategories = $('td', this);
            $(oTable_categories.fnSettings().aoData).each(function (){$(this.nTr).removeClass('row_selected');});
            $(event.target.parentNode).addClass('row_selected');
            current_category_text=$.trim( $(event.target).text() );
            current_category_path=$(event.target);
            $(event.target).html("<input value= '"+ $(event.target).text() +"' style='width:200px;float:right;height:17px;padding:0px;height:22px;padding-right:3px;' id='category_input_change' />");
            $(event.target).append("<ul class='styledlist' style='width:50px;float:right;'><li style='line-height:13px;' id='save_category' >ذخیره</li></ul>");
            $(event.target).append("<ul class='styledlist' style='width:50px;float:right;'><li style='line-height:13px;' id='cancel_save_category' >انصراف</li></ul>") ;
            category_row_editable=false;
            current_dlbclick=false;
            event.returnValue= false;
            return false;
         }
    });

i'm trying this codes for that: 1:

   $('#category_input_change').bind('keypress', function(e) {
      if(e.keyCode==13)
           alert('ddddd');
    });

2:

$('#category_input_change').keyup(function (e) {
  if (e.keyCode == 13)
     alert('ddddd');
});

Upvotes: 2

Views: 1627

Answers (2)

user617263
user617263

Reputation: 5

Try to using .live or .on method like

$('#category_input_change').live('keypress', function(e) {
    if(e.keyCode==13)
        alert('ddddd');
});

Upvotes: 0

nix
nix

Reputation: 3302

Try using .on(). And dont use id on category_input_change because id must be unique. Use class instead.

Like this:

$("#showCategories").on('keyup', '.category_input_change', function(){
    //your code here..
});

Upvotes: 2

Related Questions