TinyMCE Keyup Function

I am trying to run a function on Keyup of the TinyMCE Editor on new post and edit post screens.

I’m having a hard time catching the keyboard action when a user types something.

Read More
jQuery(document).ready(function() {
                setTimeout(function(){
                    var content = "tinymce";
                    var tinyMCEcontent = tinymce.editors.content.getContent();
                    console.log(tinyMCEcontent.length);
                },3000);
            });

This was my attempt at getting the content of the TinyMCE editor. I am able to see the length. How can I run this function on Keyup? I have tried something like this:

jQuery(document).ready(function() {
          jQuery("#tinymce").keyup(function() {
                setTimeout(function(){
                    var content = "tinymce";
                    var tinyMCEcontent = tinymce.editors.content.getContent();
                    console.log(tinyMCEcontent.length);
                },3000);
          });
 });

But it isn’t catching the keyup at all.

What I am trying to do is set a limit on the post type content.

Related posts

2 comments

  1. For WordPress 3.9+ running tinymce 4:

        window.onload = function () {
            tinymce.get('content').on('keyup',function(e){
                console.log(this.getContent().replace(/(<[a-zA-Z/][^<>]*>|[([^]]+)])|(s+)/ig,'').length);
            });
        }
    

Comments are closed.