Last active
August 29, 2015 14:17
-
-
Save SMaguina/33a78e4b695f81d9c99e to your computer and use it in GitHub Desktop.
lesson 2-javascript/jquery
This file contains 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 characters
$("#message").on("keyup", function() { | |
console.log("keyup happened"); // This console log ensures the .on() method event listener is in effect | |
var charCount = $("#message").val().length; // Method chaining occurs to return the # of characters in a DOM element; variable contains multiple data types/methods | |
console.log(charCount); // This console log ensures the variable for character count is in effect and the # of characters are printed in the console | |
$("#char-count").html(charCount); | |
if(charCount > 50) { // Conditional statements start here to change color of text based on character count value | |
$("#char-count").css("color", "red"); | |
} else { | |
$("#char-count").css("color", "black"); | |
} | |
}); | |
In index.html file, add the following code snippet under the Contact message form to return the # of characters in a DOM element: | |
<p id="char-count"></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment