JSFiddle - React, Tailwind, and code Playground

by oms02

HTML

<div id="texto" contenteditable="true">afds</div>

JavaScript

var lugar = '#texto';
var max = 10;
$(lugar).keyup(function(e){
	contador(lugar,max,e);
}).keydown(function(e){
	contador(lugar,max,e);
});

function contador(lugar,max,e){
	if(e.which != 8 && e.which != 37 && e.which != 38 && e.which != 39 && e.which != 40 && 
$(lugar).text().length > max)
	{e.preventDefault();}
}