Reputation: 35
I have a html <div id = "a"></div>
and js code:
const a = document.getElementById("a");
a.contentEditable = true;
and I want to set a max length of 30 to the a like input text. I've tried using
a.addEventListener("input",() => {
if(a.innerText.length == 30) {
a.contentEditable = false;
}
but the outcome is not satisfing. It did stop the further input but also stoped me to edit a.
Upvotes: 0
Views: 109
Reputation: 35
I got the desired result by adding
a.innerText = a.innerText.slice(0,30);
Upvotes: 1