Javascript Ajax jQuery Html PHP Example Quiz New MORE
Need a Website Or Web Application Or Any Help.Contact Us: +91 9437911966 (Whatsapp) Note: Paid Service

How to Count Remaining Character in jQuery with Demo

<!Doctype html>
<html>
<head>
    <title>Twitter Style Remaining Character Count using jQuery</title>
    <style>
        body {
            width: 610px;
        }

        #text-content {
            padding: 10px;
            border: #F0F0F0 1px solid;
            border-radius: 4px;
            background-color: #FFF;
        }

        #text-content:focus {
            outline: 0;
        }

        #character-count {
            color: #A0A0A0;
            padding: 15px 0px;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<textarea id="text-content" cols="70" rows="4" onKeyup="count_remaining_character()" placeholder="At least 100 character"></textarea>
<div id="character-count" align="right">150</div>
<script>
    function count_remaining_character() {
        var max_length = 100;
        var character_entered = $('#text-content').val().length;
        var character_remaining = max_length - character_entered;
        $('#character-count').html(character_remaining);
        if (max_length < character_entered) {
            $('#character-count').css('color', '#FF0000');
        } else {
            $('#character-count').css('color', '#A0A0A0');
        }
    }
</script>
</body>
</html>

Run it yourself

Demo

Twitter Style Remaining Character Count using jQuery
150