Alexander Savin
Alexander Savin

Reputation: 6442

jQuery keypress event doesn't work on elements inside contenteditable section

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?

Upvotes: 1

Views: 1157

Answers (1)

Dieterg
Dieterg

Reputation: 16368

You need to attach your event to the section element like so:

$('section').on('keypress', function(e) {
   alert('typed'); 
});

http://jsfiddle.net/Dieterg/j9mHF/1/

Upvotes: 1

Related Questions