For some reason, when I add a class to various inputs (after a user presses submit), this function does not record keypresses being made within those inputs. I must be doing something fundamentally wrong as I've tried $('incomplete_required').keyup(){}
and what is below, as it seems .on()
is more modern..
$(document).ready(function(){
$('.incomplete_required').on("keyup", function(){
console.log('keyed');
});
});
What have I done wrong here?
Thank you
If you are dynamically changing elements in the dom - it is best to delegate the event to an existing parent in the dom
$(document).ready(function(){
$('body').on("keyup",'.incomplete_required', function(){
console.log('keyed');
});
});
Obviously replacing body
with the closest parent element that exists on dom ready
By delegating - the event will bubble up to the "parent" element - which is where the event is handled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With