Reputation: 690
I feel that I might be overlooking something here. I wan to display the character count of a textarea in a <span>
element underneath the <textarea>
. I am using the following jQuery and HTML:
jQuery:
$('#ws3 .textarea textarea[name="company-description"]').keyUp(function() {
var charLength = $(this).val().length;
$('span#charCount').html(charLength + ' of 250 characters used');
if($(this).val().length > 250)
$('span#charCount').html('<strong>You may only have up to 250 characters.</strong>');
});
HTML:
<div id="ws3" class="ws-section">
<label for="company-description">Describe your company for us</label>
<div class="textarea">
<textarea id="company-description" name="company-description" class="ws-required"></textarea>
</div>
<span id="charCount">charCount</span>
</div>
Also, all jQuery code following this block does not work, almost as if the browser has stopped reading the .js file at this block of code.
Upvotes: 0
Views: 1938
Reputation: 79830
There is no keyUp
function.. change it to keyup
and then it should work fine..
$('#ws3 .textarea textarea[name="company-description"]').keyup(function() {
Tips:
js
file or next <script>
blockkeyUp
Error: $("#ws3 .textarea textarea[name=\"company-description\"]").keyUp is not a function
Upvotes: 3
Reputation: 13461
There is no keyUp
function in jQuery the function name is keyup
Upvotes: 2