I am referencing the CKEditor JQuery adapter (as well as jquery 1.6 lib)
<script type="text/javascript" src="../ckeditor/ckeditor.js" />
<script type="text/javascript" src="../ckeditor/adapters/jquery.js" />
And declaring, my CKEditor instance as:
<textarea id="editor1" name="editor1"></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1', {
toolbar : 'Basic',
uiColor : '#0579b3',
resize_enabled: false
});
</script>
In Jquery I am doing:
var value = $('textarea.editor1').getData();
If I try to alert the var value, I get undefined.
Is there something wrong with how I am trying to get the textarea value w/ JQuery? I have also tried .val() but no luck.
The alert happens after a button is pressed.
If you need to get the actual data from CKEditor 4 at any moment using JavaScript, use the editor. getData() method as described above.
CKEditor 4 offers native jQuery integration through its jQuery Adapter (a jQuery plugin basically). It provides deep integration of CKEditor 4 and jQuery that lets you use the native features of jQuery when using CKEditor 4.
To start, create a simple HTML page with a <textarea> element in it. You will then need to do two things: Include the <script> element loading CKEditor 4 in your page. Use the CKEDITOR.
Try:
var value = CKEDITOR.instances['editor1'].getData();
//or
$('#editor1').ckeditor(function( textarea ){
$(textarea).val();
});
Hope it helps
You could integrate a function on JQuery
jQuery.fn.CKEditorValFor = function( element_id ){
return CKEDITOR.instances[element_id].getData();
}
and passing as a parameter the ckeditor element id
var editor1_value = $().CKEditorValFor('editor1');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With