Source Code

Countable is a JavaScript function

  • sacha
  • 19 November 2013 at 13:24
  • Javascript
  • 547
  • 44
  • United States

Author: sacha Language: United States
License: Freeware
Size: 0 KB
Downloads: 26 times


Countable is a JavaScript function to add live paragraph-, word- and character-counting to an HTML element. Countable is a zero-dependency library and comes in at 1KB when minified and gzipped.


Countable offers easy-to-use methods you can use in your project. and Countable.once() accept one or more HTML elements and a callback that receives one parameter — holding all counted values — and this bound to the relevant element.

Available methods

To enable full live-counting on an element, call

var area = document.getElementById('area'), function (counter) {

In order to remove the Countable functionality from an element, call Countable.die().


There might be situations where you only want to count paragraphs, words and characters of an element once, i.e. if you want to display the word count of an article on your blog. In order to achieve this, call Countable.once().

Countable.once(area, function (counter) {

Countable also provides a handy method to check if live-counting functionality is enabled on an element: Countable.enabled().


Options and Countable.once() both accept a third argument, an options object that allows you to change how Countable treats certain aspects of your element's text.

  hardReturns: false,
  stripTags: false

By default, paragraphs are split by a single return (a soft return). By setting hardReturns to true, Countable splits paragraphs after two returns.

Depending on your application and audience, you might need to strip HTML tags from the text before counting it. You can do this by setting stripTags to true.

comments powered by Disqus

Related Code

Passing JavaScript variables to PHP

Create Dynamic Bar Graph or Chart in php

Securimage with Image


A Simple PHP Image Resize Code

How Create a Zip File Using PHP

Icon Extractor - full delphi source code

Func-In Delphi Example

Create Search and Get in The Middle String

PHP Script for PING


Tag Linked