You can do this in this way:
use this jQuery plugin for pre & post paste events:
$.fn.pasteEvents = function( delay ) { if (delay == undefined) delay = 20; return $(this).each(function() { var $el = $(this); $el.on("paste", function() { $el.trigger("prepaste"); setTimeout(function() { $el.trigger("postpaste"); }, delay); }); }); }; Now you can use this plugin;:
var pasteSaveSel=[]; $('#txt').on("prepaste", function() { $(this).find("*").each(function(){ pasteSaveSelvar tmp=new Date.pushgetTime(); $(this).prop("tagName").toLowerCasedata()"uid",tmp); }); }).pasteEvents(); $('#txt').on("postpaste", function() { var i=0; $(this).find("*").each(function(){ if(pasteSaveSel[i]!=$$(this).prop("tagName").toLowerCasedata("uid")){ $(this).removeAttrremoveClass("style"); } $(this).removeAttr("style id"); i++;} }); }).pasteEvents(); Explaination
First saveset a uid for all the existing nodes tag name in an array PRE PASTE eventelements as data attribute.
Then after save compare all nodes name with the previous one in POST PASTE event. So by comparing you can identify the newly inserted one because they will have a uid, then just remove style/class/id attribute from newly created elements, so that you can keep your older formatting.