File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Document</ title >
7+ < script defer src ="script.js "> </ script >
8+ </ head >
9+ < body >
10+ < section >
11+ < h3 > Example character limit comment component!</ h3 >
12+ < label for ="comment-input ">
13+ Please enter your comment in the text area below
14+ </ label >
15+ < textarea
16+ id ="comment-input "
17+ name ="comment-input "
18+ rows ="5 "
19+ maxlength ="200 "
20+ > </ textarea >
21+ < p id ="character-limit-info "> You have 200 characters remaining</ p >
22+ </ section >
23+ </ body >
24+ </ html >
Original file line number Diff line number Diff line change 1+ // const textarea = document.querySelector("textarea");
2+ // const remainingCharacters = textarea.maxLength - textarea.value.length;
3+
4+ // const charactersLeftP = document.querySelector("#character-limit-info");
5+ // charactersLeftP.innerText = `You have ${remainingCharacters} characters remaining`;
6+
7+ // function updateCharacterLimit() {
8+ // const remainingCharacters = textarea.maxLength - textarea.value.length;
9+ // const charactersLeftP = document.querySelector("#character-limit-info");
10+ // charactersLeftP.innerText = `You have ${remainingCharacters} characters remaining`;
11+ // }
12+
13+ // textarea.addEventListener("keyup", updateCharacterLimit);
14+
15+ // refactor version
16+ const textarea = document . querySelector ( "textarea" ) ;
17+
18+ updateCharacterLimit ( ) ;
19+
20+ function updateCharacterLimit ( ) {
21+ const remainingCharacters = textarea . maxLength - textarea . value . length ;
22+ const charactersLeftP = document . querySelector ( "#character-limit-info" ) ;
23+ charactersLeftP . innerText = `You have ${ remainingCharacters } characters remaining` ;
24+ }
25+
26+ textarea . addEventListener ( "keyup" , updateCharacterLimit ) ;
You can’t perform that action at this time.
0 commit comments