Giter Site home page Giter Site logo

jquery-maxlength's Introduction

jQuery.maxlength

jQuery.maxlength is a lightweight jQuery character counter and countdown for inputs and textareas.

Basic usage

<input type="text" maxlength="50"/>
$("input").maxlength();

Generated HTML:

<input type="text" maxlength="50"/>
<div class="maxlength">50 characters left</div>

jQuery.maxlength options

text (string, default: '%left characters left')

Text to be displayed inside the .maxlength div. You can use whatever text you want, or even HTML.

You can also use variables inside that string: %length is the length of the text in the field, %maxlength is the maximum length, and %left is the number of characters left before reaching that maximum length.

counterContainer (jQuery object, default: null)

The element inside of which to insert the .maxlength div. If no counterContainer is specified, the div will be inserted right after the field.

jQuery.maxlength events

Events are triggered on the field. They all use the maxlength namespace.

update.maxlength

Triggered when the length of the text in the field changes.

This event passes six parameters to its event handler: the event object, the field's DOM element (as a jQuery object), the last length of the text in the field, the current length, the maximum length and the number of characters left before reaching that maximum length.

$("input").bind("update.maxlength", function(event, element, lastLength, length, maxLength, left){
    console.log(event, element, lastLength, length, maxLength, left);
});

Notes

  • If jQuery.maxlength is called on an input or a textarea that doesn't have any maxlength attribute (or a falsy one), it just won't do anything.
  • jQuery.maxlength works with jQuery 1.4 and above.

jquery-maxlength's People

Contributors

xuanhoa88 avatar xuanntvnext avatar

Stargazers

Olibia Tsati avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.