Search code examples
javascriptjqueryflipclock

FlipClock.js on event is not a function


I've an error with FlipClock.js when I try to get event with on method.

My code:

var counter = $('.counter').FlipClock(0, {
    clockFace: 'Counter',
    minimumDigits: 3
}).on('set:time', function() {
    alert('test');
});

I have this on console:

Uncaught TypeError: $(...).FlipClock(...).on is not a function


Solution

  • By looking into your jsfiddle example, I can see that you do not react on the jQuery element.

    I have tested your code with following changes:

    $(document).ready(function () {
    
      var counter = $('.counter').FlipClock(0, {
        clockFace: 'Counter',
        minimumDigits: 3,
        events: true
      });
      counter.$el.on('set:time', function() {
        alert('test event');
      });
    
      $(document).on('click', 'button', function () {
        alert('Set!');
        counter.setTime(10);
      });
    });
    

    This works perfectly!

    In my correction of the, I am listening on the event by the jQuery element.

    Please vote and approve the answer.