Last active
December 19, 2019 20:08
-
-
Save thatdevgirl/c4e3199869258224353a5ecaf2fee271 to your computer and use it in GitHub Desktop.
Revisions
-
thatdevgirl revised this gist
Dec 19, 2019 . 1 changed file with 19 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,25 @@ <!DOCTYPE html> <html lang="en"> <head> <title>Character Count using jQuery</title> </head> <body> <header> <h1>Character Count using jQuery</h1> </header> <main> <textarea class="countMe"></textarea> </main> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script src="character-counter.js"></script> <script> $( '.countMe' ).characterCount( 250 ); </script> </body> </html> -
thatdevgirl created this gist
Dec 19, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ <!DOCTYPE html> <html lang="en"> <head> <title>Character Count using jQuery</title> </head> <body> <header> <h1>Character Count using jQuery</h1> </header> <main> <textarea class="countMe"></textarea> </main> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script src="character-counter.js"></script> <script> $( '.countMe' ).characterCount( 250 ); </script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // Append a character count element in the DOM. $.fn.characterCount = function(max) { if (this.val() == undefined) { return false; } // Calculate remaining characters based on the initial value of the field. var remaining = max - this.val().length; // Display initial remaining character count message. this.after( '<div class="characterCount">' + '(<span>' + remaining + '</span> characters remaining)' + '</div>'); // Set the max length of the text area. this.attr('maxlength', max); // Keyup event to update remaining character count message. var parent = this.parent(); this.keyup(function() { var remaining = max - $(this).val().length; $('.characterCount span', parent).html(remaining); }) };