Javascript charactor counter script

Javascript charactor Counter script. onClick button count characters, textarea onInput (paste change keyup) count characters

1

on Click function count characters

0
<textarea id="char-text" rows="10" cols="50"></textarea>
<button id="count-btn">count characters</button>
<div id="char-length"></div>

<script>
document.getElementById("count-btn").onclick = function () {
  var total_length = document.getElementById("char-text").value.length;
  document.getElementById("char-length").innerText = total_length;
};
</script>
2

on change function count characters

0
<textarea id="char-text" rows="10" cols="50"></textarea>
<div id="char-length"></div>

<script>
var char_text = document.getElementById("char-text");
char_text.onchange = function () {
    var total_length = char_text.value.length;
    document.getElementById("char-length").innerText = total_length;
};
</script>
3

on Input function (paste change keyup) count characters

0
<textarea id="char-text" rows="10" cols="50"></textarea>
<div id="char-length"></div>

<script>
var char_text = document.getElementById("char-text");
char_text.oninput = function () {
    var total_length = char_text.value.length;
    document.getElementById("char-length").innerText = total_length;
};
</script>