I have 3 textareas and 3 divs under each in which some html should be showed.
<textarea class="tinymce" rows="2" cols="20"></textarea><br />
<div class="character_count"></div>
<textarea class="tinymce" rows="2" cols="20"></textarea><br />
<div class="character_count"></div>
<textarea class="tinymce" rows="2" cols="20"></textarea><br />
<div class="character_count"></div>
When i am typing some text, in the div with class character_count below the textarea i am typing in, should the characters be displayed. I do not succeed in it:
This is my js:
tinymce.init({
selector: '.tinymce',
width: 400,
setup: function (ed) {
ed.on('keyup', function (e) {
var count = CountCharacters();
$(this).closest(".character_count").text("Characters: " + count); // find the closest div with class .character_count and show the html
});
}
});
function CountCharacters() {
var body = tinymce.activeEditor.getBody();
var content = tinymce.trim(body.innerText || body.textContent);
return content.length;
};
Fiddle to test: https://jsfiddle.net/4vron96z/3/
BTW: $(".character_count").text("Characters: " + count); does work but then the html is displayed in all the 3 divs...