aboutsummaryrefslogtreecommitdiff
path: root/microblog.js
blob: 03e8d118729a08156eb24b3ecae8f1cec12e896e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';

const textarea = document.querySelector('textarea[name="content"]');
const charCount = document.querySelector('#count');

if (textarea) {
	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);
}