Skip to content

Instantly share code, notes, and snippets.

@SMaguina
Last active August 29, 2015 14:17
Show Gist options
  • Save SMaguina/33a78e4b695f81d9c99e to your computer and use it in GitHub Desktop.
Save SMaguina/33a78e4b695f81d9c99e to your computer and use it in GitHub Desktop.
lesson 2-javascript/jquery
$("#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