I have a contentEditable Div and I want remove any formatting especially for copy and paste text.
document.querySelector('div[contenteditable="true"]').addEventListener("paste", function(e) {
e.preventDefault();
var text = e.clipboardData.getData("text/plain");
document.execCommand("insertHTML", false, text);
});
It is simple: add a listener to the "paste" event and reeformat clipboard contents.
Here another example for all containers in the body:
[].forEach.call(document.querySelectorAll('div[contenteditable="true"]'), function (el) {
el.addEventListener('paste', function(e) {
e.preventDefault();
var text = e.clipboardData.getData("text/plain");
document.execCommand("insertHTML", false, text);
}, false);
});
Saludos.