[Solved] Setting min and max font size for a fixed-width text div that accepts variable text [closed]


Add an event listener to some changing property and then change the font size accordingly.

document.getElementById("testInput").addEventListener("keyup", function(){
 var inputText = document.getElementById("testInput").value; document.getElementById("test").innerHTML = inputText;
if(inputText.length > 10){
  document.getElementById("test").style.fontSize = "8px"; 
}else if(inputText.length > 5){
  document.getElementById("test").style.fontSize = "10px"; 
}else{
  document.getElementById("test").style.fontSize = "12px"; 
}  
 });
<input id="testInput">
<div id="test"></div>

1

solved Setting min and max font size for a fixed-width text div that accepts variable text [closed]