I have been working with the Keyup method of jQuery and it doesn’t seem to work for me. I went to create this on Jfiddle and sure enough it works there. But when upload it to a website or run it locally it does not work. What am I doing wrong here?
<html>
<head>
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
$('#TAcomments').keyup(function() {
var textCount = $(this).val().length;
if(textCount <= 10) {
$('#TAcomments').stop().animate({ fontSize : '22px' });
}
if(textCount > 10) {
$('#TAcomments').stop().animate({ fontSize : '16px' });
}
if(textCount > 20) {
$('#TAcomments').stop().animate({ fontSize : '14px' });
}
if(textCount > 30) {
$('#TAcomments').stop().animate({ fontSize : '10px' });
}
});
</script>
</head>
<body>
<textarea id="TAcomments" style="width: 400px; height: 300px; font-size: 22px;"></textarea>
</body>
</html>
You need to wait until the document is ready.
jsfiddle defaults to running code after the onload event.