hilios / jQuery.countdown

The Final Countdown plugin for jQuery
http://hilios.github.io/jQuery.countdown/
MIT License
2.31k stars 720 forks source link

'Uncaught TypeError: $(...).countdown is not a function' - may be correct! #341

Open paskainos opened 1 year ago

paskainos commented 1 year ago

TL;DR: jquery.countdown and jquery-countdown are different repos. Save yourself hours, be sure to install jquery-countdown not jquery.countdown.

Simply stated: .countdown is not defined in jquery.countdown, rather, it is camel case, i.e. .countDown. Thus, Uncaught TypeError: $(...).countdown is not a function is the correct outcome / output if one is after TFC, but has erroneously installed jquery.countdown instead of jquery-countdown. So, if one has 'done everything right' and yet remains flummoxed (e.g. 'why won't this silly package update past v1.2.8...??') odds are, this is the culprit.

Having used this handy dandy library in the past, but not for some time, and battling this dread error again, I would be remiss not to clearly, once and for all, briefly articulate the precise nature of the exact error by which so many have undoubtedly been led astray. It is simply this:

It is the difference between the "." and the "-". jquery.countdown and jquery-countdown are two different libraries. The instructions -- at The Final Countdown - jQuery.countdown page, for instance -- do not make that distinction clear, in fact leading to the error. The libraries are inadvertently somewhat comingled throughout the docs and issues, such that jquery.countdown is being pulled down, and jquery-countdown is being called. So, one must make sure to install jquery-countdown and not jquery.countdown.

For the record, jquery@2.2.4 and jquery-countdown@2.2.0 (latest, currently, for jQuery v2.2.0) work. So for example, with them installed (in that order, obviously, and correct paths called) this:

<div id="christmas-countdown"></div>

works with this:

<script type="text/javascript">
  $("#christmas-countdown")
  .countdown("2022/12/25", function(event) {
    $(this).text(
      event.strftime('%D days %H hrs %M min %S sec')
    );
  });
</script>

And require('jquery-countdown') is not 'required' (unnecessary). I hope that helps someone down the line -- perhaps even me... next time...

P.S. Sorry about the book. It was catharsis...