This code will save all changes to contenteditable in an array. You can manually save the current state by calling save_history() or attach this function to any event (in the example, keydown ). I encoded a check for equality of states, so if you associate save_history with a click event, it will not save state 10 if you click 10 times without changes in the editor. This code will work in every browser that can run jQuery:
#text_undo.disabled,#text_redo.disabled{ color: #ccc; }
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <button id="text_undo" class="disabled">Undo</button><button id="text_redo" class="disabled">Redo</button> <div id="editor" contenteditable="true">Some editable HTML <b>here</b></div> </body> </html>
source share