jquery_counter /

Filename Size Date modified Message
27 B
1.1 KB
1.9 KB
828 B
818 B

jQuery counter plugin


This plugin gives you a nice and clean way to create callbacks that would be called after several conditions are met. It's primary use is to wrap functions that require several ajax requests to be fullfilled (as we don't know in what order they will arrive).


The plugin should work from jQuery 1.2 up.


  1. Create the counter object by calling $.counter(fn[, scope[, args]]) on the function you want to act as a callback. Optionally you can pass execution scope and argument list.
  2. Call the created object's require('name') method for every condition specifying a string that would act as an id for this condition.
  3. Use a call to counter's signal('name'[, args]) to signal that the condition was met. You can optionally modify the argument list to the function.


This code will load both header and footer elements and will call the main_callback() after last of them is loaded.

function main_callback() {
        // Do something when both header and footer are loaded

main_callback = $.counter(main_callback);

$('#header').load('http://example.com/header.html', function () {
        // Do something with the header

$('#footer').load('http://example.com/footer.html', function () {
        // Do something with the footer

Howto run demo

  1. Install paste:

    pip install Paste
  2. Download jquery and put it in the main directory.

  3. Run the demo server:

    cd demo
    python demo.py
  4. Point your browser to