100-project-100-days-website/100_projects/30-calculate-textarea-text-while-writing/main.js
2023-03-23 16:44:03 +03:00
Ask

22 lines
643 B
JavaScript

{ee385364eac7cde87b5d4eee8f031c61f2adc02a true 643 main.js 0xc001da7180}

var myTextarea = document.getElementById('myText'),
mySpan = document.getElementById('mySpan');
myTextarea.onkeyup = function() {
'use strict';
mySpan.textContent = 100 - this.value.length;
if (mySpan.textContent < 0){
mySpan.style.color = '#F00';
} else {
mySpan.style.color = '#008000';
}};
// 2 Code If Short
// mySpan = document.getElementById('mySpan');
// document.getElementById('myText').onkeyup = function() {
// 'use strict';
// mySpan.textContent = 50 - this.value.length;
// mySpan.textContent < 0 ? mySpan.style.color = '#F00' : mySpan.style.color = '#000';
// };