javascript - Undo for div tag -
i have div tag contenteditable = 'true'. when enter text keyboard , call undo function (document.execcommand('undo',false, null)), of text entered deleted. want undo last character typed. how can that?
function doundo() { document.execcommand('undo',false, null); } <!doctype html> <html> <head> <script src="formulas.js"></script> <link rel="stylesheet" href="styles.css" type="text/css" media="screen" /> </head> <body id="main" spellcheck="false"> <span contenteditable="false"> <button onclick="doundo()">undo</button> </span> <div id = "maindiv"contenteditable="true">a</div> </body> </html>
in doundo() instead of calling execcommand remove last character div, if not empty.
e.g.
function doundo() { var maindiv = document.getelementbyid('maindiv') maindiv.innerhtml = maindiv.innerhtml.substr(0, maindiv.innerhtml.length - 1); }
Comments
Post a Comment