blob: bcb207a69ec755f6da00eb79ec06df839f48b5aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
'use strict';
const textarea = document.querySelector('textarea[name="content"]');
const charCount = document.querySelector('#count');
const maxCount = parseInt(textarea.getAttribute('maxlength'));
if (textarea.value.length > 0) {
const textLength = [...textarea.value].length;
charCount.textContent = maxCount - textLength;
} else {
charCount.textContent = maxCount;
}
textarea.addEventListener('input', function () {
const textLength = [...this.value].length;
charCount.textContent = maxCount - textLength;
}, false);
|