I would like to detect when a user has pressed a key in a contenteditable div. However, the div is loaded dynamically and I would only like catch the first key press.
I would like the same outcome as jquery catch a first keypress only? but for dynamic content.
My code so far:
$(document).on('keypress',"#divid",function(){});
If you only want to catch the first keypress, you can use
onefor that (yes, reallyone— it’s a horrible pun):Or explicitly remove the handler when it’s fired (perhaps after checking some condition):
(Yes, heaven help us, the function is really called
off.)