JavaScript
Article

jQuery Simple Characters Counter

By Sam Deering

jQuery code snippet to show a live count of the number of characters that a user is inputting into the input field on a page.

jQuery Code

$(document).ready(function() {
    $("input[id='input-text']").keyup(function count(){
        counter = $("input[id='input-text']").val().length;
            $("#count").html(counter);
    });
});

HTML Code

See Live Demo

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.