I’ve run into this several times now, where I wish to use document.on() to manipulate an element, but cannot figure out how to use .on() without an event.
I often use ajax to inject elements into the DOM and frequently need to use document.on() to bind to those injected elements. This works perfectly when I wish to select an element and get at its information.
For example, to attach to a selector via the click event, one writes:
$(document).on('click', '.mledit', function(event) {
alert($(this).val());
}
However, what if I wish to set focus to that element? How would I do that? I have tried:
$(document).on('focus', '.mledit');
and am at a loss as to what else to try.
The reason I need to do this is because at the moment (and I’ve been here before), the standard $('.mledit').focus(); is not working. Everything else seems alright, but that one instruction is not. So, I’m wondering if using document.on() is even possible in such a case.
This: