Skip to content

Instantly share code, notes, and snippets.

@nimrossum
Created December 20, 2013 20:34
Show Gist options
  • Save nimrossum/8061075 to your computer and use it in GitHub Desktop.
Save nimrossum/8061075 to your computer and use it in GitHub Desktop.
Character count
<html>
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function () {
$('textarea').keyup(function() {
var lc = $(this).val().replace(/[^A-Z]/gi, "").length,
s = (lc == 1) ? '':'s';
$('output').text(lc + ' letter' + s);
});
});
</script>
<style>
body {
font-family: sans-serif;
text-align: center;
}
textarea {
height: 150px; width: 300px;
font: 20px sans-serif;
padding: 7px;
outline: none;
resize: none;
text-align: center;
border-radius: 5px;
border: 1px #bbb solid;
}
</style>
</head>
<body>
<h1>
<output>0 letters</output>
</h1>
<textarea autofocus></textarea>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment