I have section element, which is contenteditable=true, and it contains another elements like images and paragraphs created by user.
<section contenteditable=true>
<p>Hello there</p>
</section>
If I attach jQuery on('keypress') event to the section, or to p element, it doesn't work. 'Click' events work just fine.
Here is jsFiddle: http://jsfiddle.net/j9mHF/
Is it so that in order to get keypress events, the element must be contenteditable enabled?
You need to attach your event to the section element like so:
$('section').on('keypress', function(e) {
alert('typed');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.