Home » Jquery » jquery – Why keyup function is not working in CKEDITOR?-Exceptionshub

jquery – Why keyup function is not working in CKEDITOR?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment


In my application, I have a textarea and I am handling it with ck editor. I am trying to call the keyup function on ck editor and print a text to console on the condition whether it has input or not. But it is not working as I expected and I am unable to find the error as it is not at least printing any errors to the console. Also, I want to get only the text from ck editor (except white spaces) to the variable editorInput. I am pasting my code here, please someone look into this and correct my error and modify it to get only the text. Thanks in advance.

CK Editor

<div class="form-group {{ $errors->has('template_content') ? 'has-error' : '' }}">
    {{ Form::label('template_content', 'Template Content') }}
    {{ Form::textarea('template_content', null, array('class' => 'form-control', 'id' => 'ckeditor', 
    'name' => 'ckeditor', 'required', 'data-error="Template content is required"')) }}
    {!! $errors->first('template_content', '<span class="help-block">:message</span>') !!}
    <div class="help-block with-errors"></div>

Keyup Function

$(document).ready(function () {
        CKEDITOR.instances.ckeditor.on('key', function() {
            var editorInput = CKEDITOR.instances["ckeditor"].getData();
            if(editorInput == '') {
            else {
How to&Answer:

here is an example with just js.

<!DOCTYPE html>
                <meta charset="utf-8">
                <script src="https://cdn.ckeditor.com/4.13.1/standard/ckeditor.js"></script>
                <textarea name="editor1"></textarea>
                        CKEDITOR.replace( 'editor1' );