# Option: cleanup_callback

This option enables you to add custom cleanup logic to TinyMCE. This function is called when the cleanup process is executed this process occures when the editor saves/submits content, user hits the cleanup button and when the HTML editor dialog is presented. The format of this function is: customCleanup(type, value). Where type can be "get_from_editor" when the contents is extracted from TinyMCE for example when the user submits the form. The "insert_to_editor" type value gets passed when new contents is inserted into the editor on initialization or when the HTML editor dialog commits new content. The "get_from_editor_dom" value is executed when cleanup process has a valid DOM tree and is extracted from the editor. The "insert_to_editor_dom" gets passed when the editor has a valid DOM tree and contents has been inserted into the editor. The example below illustrated all these types.

### Example of usage of the cleanup_callback option:

    function myCustomCleanup(type, value) {
    	switch (type) {
    		case "get_from_editor":
    			alert("Value HTML string: " + value);

    			// Do custom cleanup code here

    			break;

    		case "insert_to_editor":
    			alert("Value HTML string: " + value);

    			// Do custom cleanup code here

    			break;

    		case "get_from_editor_dom":
    			alert("Value DOM Element " + value);

    			// Do custom cleanup code here

    			break;

    		case "insert_to_editor_dom":
    			alert("Value DOM Element: " + value);

    			// Do custom cleanup code here

    			break;
    	}

    	return value;
    }

    tinyMCE.init({
    	...
    	cleanup_callback : "myCustomCleanup"
    });