How to clear TINYMCE contents after ajax action using jquery

I am adding content to some input and textarea fields using the jquery ajax function. TINYMCE uses textare only.

However, after ajax, the text in TINYMCE is not updated and remains.

How can I clear the contents in TINYMCE using jquery?

The current current code.

//on submit event $("#specformentry").submit(function(event){ event.preventDefault(); if(checkForm()){ // var href = $(this).attr("href"); submitinput.attr({ disabled:true, value:"Sending..." }); //$("#send").blur(); //send the post to shoutbox.php $.ajax({ type: "POST", url: "../../Ajaxinsertspec", data: $('#specformentry').serialize(), complete: function(data){ update_entry(); specdesc.val(''); datecreated.val(''); detailstext.val(''); // this code is supposed to empty the INYMCE content, but it does not //reactivate the send button submitinput.attr({ disabled:false, value:"Enter Spec" }); } }); } else alert("Please fill all fields!"); //we prevent the refresh of the page after submitting the form return false; }); 

And here is the HTML part

 <div id="enterlabel"><label for="spec_details">Click me to enter Spec Details</label></div> <div style="display: block;" id="textarea"> <textarea style="display: none;" name="spec_details" cols="90" rows="12" id="detailstext"></textarea> <span class="mceEditor defaultSkin" id="detailstext_parent"> <table style="width: 100px; height: 100px;" class="mceLayout" id="detailstext_tbl" cellpadding="0" cellspacing="0"> <tbody><tr class="mceFirst"> <td class="mceToolbar mceLeft mceFirst mceLast"><a href="#" accesskey="q" title="Jump to tool buttons - Alt+Q, Jump to editor - Alt-Z, Jump to... ... 
+7
javascript jquery tinymce
source share
3 answers

You do not need jQuery to remove tinymce. Get the tinymce instance by id and set the content to '' (equal to empty) with

// ID of the first page editor can be found in tinymce.editors [0] .id

 var tinymce_editor_id = 'my_tinymce_id'; tinymce.get(tinymce_editor_id).setContent(''); 
+14
source share

This worked for me:

 tinyMCE.activeEditor.setContent(''); 

Especially if this is the only editor existing on your page.

+8
source share

Try using the code below

 if (typeof(tinyMCE) != 'undefined') { $('#edit-comment').val(''); // Removes all paragraphs in the active editor } 
+2
source share

All Articles