Skip to content Skip to sidebar Skip to footer

Jquery: Stopwatch

I'm using the stopwatch code I found here: http://www.kellishaver.com/projects/stopwatch/ (function($) { $.fn.stopwatch = function() { var clock = this; var tim

Solution 1:

How about:

$('#clock1').find('.stop').trigger('click');

Solution 2:

You can add a small API to the code and attach it using $.data:

var api = {
    stop: function() {
        stop.click(); // this should probably be improved, but you get the idea
    }
 };
 $(clock).data('stopwatch', api);

Then use:

$('#clock1').data('stopwatch').stop();

You can also add the reset and start functions to the API using the same logic. A good thing here is that you can improve the execution code on a coffee break later without changing the way external programs uses the API.

Post a Comment for "Jquery: Stopwatch"