how to clear ckeditor with jquery

前端 未结 4 405
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 01:50

How can i clear the ckeditor textarea with jquery at the click of a button/link?

I have tried this : $(\"textarea.editor\").val(\'\'); and $(\"tex

相关标签:
4条回答
  • 2021-01-04 01:57

    The below code clears the value in the ckeditor textarea. This will works 4.4 version also.

          CKEDITOR.instances['content'].setData('');
    

    Content is the id of the particular text-area.

    0 讨论(0)
  • 2021-01-04 02:11

    Try it may helpful.

    function CKupdate(){
        for ( instance in CKEDITOR.instances ){
            CKEDITOR.instances[instance].updateElement();
        }
        CKEDITOR.instances[instance].setData('');
    }   
    
    $.ajax({
       url: $('#CommunicationForm').attr("action"),
       type: $('#CommunicationForm').attr("method"),
       data: $('#CommunicationForm').serialize(),
       success: function (e) {
           if (e.error) {
              alert(e.error);
           } else {
              //Doing Clear here                          
              CKupdate();
           }
       },
       error: function (jqXHR, Status, text) {
            alert("error! " + text);
       }   
    });
    

    Call CKupdate() function when when you want to clear CKEditor text.

    0 讨论(0)
  • 2021-01-04 02:15

    In my code i had to change the text in the ckeditor programmatically but it did not work until i did a defered set. This may be helpful.

    _.defer(function () {
        it._controls.wysiwyg.setData(bodyText); // by the direct reference
        //CKEDITOR.instances.editor1.setData(''); // or this way like in the example
    }); 
    
    0 讨论(0)
  • 2021-01-04 02:17

    CKEDITOR.instances.editor1.setData('');

    Where editor1 is the id of your CKEDITOR field

    0 讨论(0)
提交回复
热议问题