so we can write a function on keyup
by using Jquery on:
$('#thing').on('keyup',function(){
//code goes here
});
but, if you want to use ajax or create the #thing
dynamically in javascript, then this will not work.
In an instance where one dynamically creates an element like that, you use the document
. The following would be used:
$(document).on('keyup','#thing',function(){
//code goes here
});
But what if we want multiple events???
The non-dynamic version is allowed. Let's say we want keyup and keypress:
$('#thing').on('keyup keypress',function(){
//code goes here
});
but the dynamic version below will not work:
$(document).on('keyup keypress','#thing',function(){
//code goes here
});
how can one use $(document).on
for multiple events on a specific selector? if it is not possible, what would be the equivalent enabling dynamic creation?