Count Words using tinymce in the front-end

A while later i decided to try it again… (needed it for a project)
this time i went for clean jquery and i got it to work!

here it is:
the working & easy to use way to count words while
they are being written inside a wp_editor both in the
html editor and visual editor.

<script type="text/javascript">
i=0;
$(document).ready(function(){
    // visual mode
    // the iframe id
    $("#description_ifr").ready(function () {
        setInterval(function(){
            var tinymceval = $('#description_ifr').contents().find('body').text();
            var wordscount = tinymceval.split(" ");
                    // you should crete a div with the 
                    // the id = #wordcount to show count
            $("#wordcount").text(wordscount.length);
        }, 5000)
    });

    // html mode
// #description is the id of the text area
    $("#description").keypress(function(){
        $("#wordcount").text(i+=1);
    });
}); 
</script>

Thanks for eveyone’s help 😉