Created
July 12, 2016 13:24
-
-
Save raulgonsales/03499d109cce37cfe1bf661aeeba6f4c to your computer and use it in GitHub Desktop.
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 characters
//control count of symbols in textarea | |
//count of symbols text | |
var symbolsLeftElement = $(".description").find(".symbols-left span"); | |
//count in number type | |
var symbolsLeftCount = parseInt(symbolsLeftElement.text()); | |
$("#description").on("input", function(){ | |
//lenght of symbols in field | |
var allCount = symbolsLeftCount - $(this).val().length; | |
if(allCount >= 0) { | |
symbolsLeftElement.text(allCount); | |
} | |
else { | |
$(this).val( $(this).val().slice(0, symbolsLeftCount) ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment