This script resize text based on the text length. All works fine but the text does not resize up when deleting characters. what's missing? Hoping there is a script guru around to help me!
$('#location').keypress(function() {
var textLength = $(this).val().length;
if (textLength < 20) {
// Do noting
} else if (textLength < 40) {
$(this).css('font-size', '16px');
} else if (textLength > 40) {
$(this).css('font-size', '24px');
}
//console.log(textLength);
});
#location {
font-size: 24px;
outline: none;
width: 200px;
height: 30px;
display: table-cell;
vertical-align: middle;
border: 1px solid #ccc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="location" placeholder="Placeholder Text" />