Skip to content

Instantly share code, notes, and snippets.

@theamith
Forked from renehuber/gist:2959472
Created January 28, 2014 14:18
Show Gist options
  • Save theamith/8668505 to your computer and use it in GitHub Desktop.
Save theamith/8668505 to your computer and use it in GitHub Desktop.
/**
* Event handler to prevent richtext and linebreaks in contentEditable DIVs
*/
$('body').on('keydown paste', 'div.editfield', function(e) {
var $field = $(e.currentTarget);
if (e.keyCode===13 && $field.hasClass('multiline')) {
return true;
} else if (e.keyCode===13 || e.type==='paste') {
setTimeout(function() {
$field.html($field.text());
},0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment