TypeError: JQuery(…).downCount is not a function

I have been banging my head against this for a bit. The countdown timer I am using has not been hooking in correctly.

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/downCount.js"></script>

wp_enqueue_script('downCount', WL_TEMPLATE_DIR_URI .'/js/downCount.js');

Those are the two ways I have tried to link my .js.

Read More
<script class="source" type="text/javascript">
        jQuery('.countdown').downCount({
            date: '09/09/2016 12:00:00',
            offset: +10
            });
</script>

There is my hook. I used to have it like this.

  <script class="source" type="text/javascript">
            $('.countdown').downCount({
                date: '09/09/2016 12:00:00',
                offset: +10
                });
    </script>

When I have it loaded like that I get almost the same error so in the browser I change it to jQuery instead of the $. When I do that it works perfectly, but when I load the page with that fix already in place I get the error in my title.

Related posts

Leave a Reply

1 comment

  1. First I’d add a jquery dependency, then add a .js file that depends on the downCount where I’d put all my downCount related script

    wp_enqueue_script('downCount', WL_TEMPLATE_DIR_URI .'/js/downCount.js', array('jquery'));
    wp_enqueue_script('downCount_script', WL_TEMPLATE_DIR_URI .'/js/my_countdown.js', array('downCount'));
    

    And in my my_countdown.js I’d add

    jQuery(document).ready(function($) {
        "use strict";
    
        $('.countdown').downCount({
            date: '09/09/2016 12:00:00',
            offset: +10
        });
    });
    

    Should be working.