Vincent
Vincent

Reputation: 325

Check ContentEditable content

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

Answers (1)

sharat87
sharat87

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

Related Questions