Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text from CK Editor textarea in JQuery

I am using CK Editor in an app.

<textarea name="contentDetails" id="contentDetails" rows="10" cols="80"></textarea>

But I can't retrieve text from that textarea. I've tried-

 var content= $("#contentDetails").text(); //and also .val() & .html()

But content variable remains empty.

Any idea?

//UPDATE - add my codes below
<script>
CKEDITOR.replace('contentDetails');

$(function () {
    $("#submitcontent").click(function (e) {
        e.preventDefault();
       var content= $("#contentDetails").text();           
    });
});

</script>
like image 402
s.k.paul Avatar asked Dec 01 '22 15:12

s.k.paul


1 Answers

Use:

var text = CKEDITOR.instances.contentDetails.getData();
like image 134
Irfan TahirKheli Avatar answered Dec 15 '22 00:12

Irfan TahirKheli