peter vries
peter vries

Reputation: 173

Disabling pasting completely in [contenteditable] div's

I'm having the luck of having to work with multiple contenteditable divs instead of textareas. I fixed almost everything, but can't find a way to completely disable pasting into the div:

$(document).on('paste',function(e) {
    e.preventDefault();
});

The paste-event does fire, but the text still gets pasted. This only has to work on Chrome (latest). Does anyone have a solution?

Upvotes: 3

Views: 2310

Answers (2)

samnu pel
samnu pel

Reputation: 914

You just need to return false

$(document).on('paste',function(e) {
    e.preventDefault();
    return false;
});

Upvotes: 4

AlexiAmni
AlexiAmni

Reputation: 402

try to change document with div

$('div').on('paste',function(e) {
    e.preventDefault();
});

Upvotes: 1

Related Questions