Skip to content

Instantly share code, notes, and snippets.

@raulgonsales
Created July 12, 2016 13:24
Show Gist options
  • Save raulgonsales/03499d109cce37cfe1bf661aeeba6f4c to your computer and use it in GitHub Desktop.
Save raulgonsales/03499d109cce37cfe1bf661aeeba6f4c to your computer and use it in GitHub Desktop.
//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