How to use $ with externally loaded javascript

I’m trying to load an external javascript file that uses jquery but references it with ‘$’. Through some digging around, I’ve cobbled together the following:

jQuery(document).ready(function(){
(function($) {
$.getScript(‘https://cdn.timekit.io/booking-js/v2/booking.min.js’, function() {
var widget = new TimekitBooking();
widget.init({
app_key: ‘test_widget_key’,
project_id: ‘1234’
// optional configuration here.. (read more under: configuration)
});
});
})( jQuery );
});

I’ve then enqueued this script in the footer. However, I keep getting the error ‘TypeError: $ is undefined’ in line 45 of the loaded script and lines 10 and 15 of this one.

Is this the best method of achieving what I want, and if so, what am I doing wrong?

Read more here:: How to use $ with externally loaded javascript

Leave a Reply

Your email address will not be published. Required fields are marked *