2

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');
});

2 Answers 2

2

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..
});
Sign up to request clarification or add additional context in comments.

4 Comments

thanks but i get this error:TypeError: $(...).on is not a function, by the way i'm using $(document).ready(function(e) { jQuery.noConflict();
Maybe you are using a version of jquery below 1.7. You may use .live() instead, but it is already deprecated. Here's the link: api.jquery.com/live
i'm using jquery-1.9.1.min.js
.on() should work. Try placing .noConflict() outside of .ready()
0

Try to using .live or .on method like

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.