javascript - How to bind change event dynamically in jquery -
i doing username availability check. made jquery ajax call, working fine , if username in use want make label , textbox in red color. purpose adding css class in callback function of $post()
method. problem have css not applying. think problem in dynamically binding event please can 1 me in this. here jquery script,
$(document).on('change', '#uname', function() { var uname = $(this).val();//get string typed user if (uname!=''){ $.post('<%=request.getcontextpath()%>/controller/usernamecheckcontroller',{'uname':uname}, function(data) { $('.status').html(data); var status = $.trim($("#status").text()); if(status=="username in use try another"){ $('#unameblock').addclass('error'); } }); } else{ $('.status').html(''); } });
help me fix please. thanks.
i think error lies on class selector
change
$.trim($("#status").text());
to
$.trim($(".status").text()); //--------^-----------------
Comments
Post a Comment