jQuery keyup() on Visual editor (TinyMCE)

WordPress is using TinyMCE editor for visual editor.

I want to hook typing in this editor. I have this code:

Read More
 tinyMCE.activeEditor.onKeyUp.add(function(ed, e) {
     console.debug(
         tinyMCE.activeEditor.getContent({format : 'raw'})
     )
 });

This is working, but I am getting error if Editor is not active in the moment when page is loaded and I am getting message “Deprecated TinyMCE API call: .onKeyPress.add(..)”

What is the best code to hook typing in this editor

Related posts

2 comments

  1. If you are using V4 of tinymce, the binding of events has changed since V3. The new way to bind events is

    tinyMCE.activeEditor.on('keyup', function(ed, e) {
       console.debug(
         tinyMCE.activeEditor.getContent({format : 'raw'});
        );
    });
    

    See this DEMO

  2. To add an event listener to an element you need to select it properly first.

    For example:
    <textarea id="visual_editor_selector"></textarea>

    In JQuery, the id attribute is called with a #, like:

    $('#visual_editor_selector')
    

Comments are closed.