Created
December 6, 2013 05:35
-
-
Save devluis/7819068 to your computer and use it in GitHub Desktop.
Live Word and Character Counter using jQuery
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>Live Word and Character Counter using jQuery</title> | |
<style> | |
textarea{ | |
width:300px; | |
height:300px; | |
} | |
</style> | |
<script> | |
function count(){ | |
var txtVal = $('textarea').val(); | |
var words = txtVal.trim().replace(/\s+/gi, ' ').split(' ').length; | |
var chars = txtVal.length; | |
if(chars===0){words=0;} | |
$('#counter').html('<br>'+words+' words and '+ chars +' characters'); | |
} | |
count(); | |
$('textarea').on('keyup propertychange paste', function(){ | |
count(); | |
}); | |
</script> | |
</head> | |
<body> | |
<textarea></textarea> | |
<div id="counter"></div> | |
</body> | |
</html> |
thanks <3
Thanks for helping, friend!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much. I have borrowed and adapted. Thanks for sharing.