Is It Possible To Capture Keydown Globally On Dynamically Added Text Inputs?
I'm using the following global jQuery to show and hide a loading div for $.ajax calls: $(document).ajaxStart(function(){ $('#loading').show(); } $(document).ajaxStop(function()
Solution 1:
you will have to use $(document).on()
for dynamically created controls.
jsfiddle: http://jsfiddle.net/G9qJE/
also you can use: $('body').on
explanation: When an event is assigned, it's only assigned to elements that currently exist on the page. If you later on other elements, there is nothing watching that watches for those elements too allow them to be used as well. That is why you need something sitting at the document level which is aware of the event and the elements you want to apply it to, so that it can watch for any new elements that match and apply that event to them as well.
$(document).on("keydown", "input[type=text]", function() {
if($(this).hasClass('ui-autocomplete-input')) {
window.suppressGlobal = true;
}
});
Post a Comment for "Is It Possible To Capture Keydown Globally On Dynamically Added Text Inputs?"