Reputation: 325
What is the way to control input user (forbidden words, in instance) in ContentEditable field (Html 5) with jQuery?
<div contentEditable="true" id="title" >
...
$('#title').focus(function()
...
doesn't work.
Thanks for help.
Vincent
Upvotes: 2
Views: 1392
Reputation: 7526
If you want to control the user's input, you should be handling the keydown
event, or something along those lines. In that event handler, if the user enters a forbidden key, you can do e.preventDefault()
so that the key is not entered in the element. For eg.
$('div[contenteditable=true]').keydown(function (e) {
e.preventDefault();
});
Upvotes: 4