Javascript embedded in the widget can't access the jquery object on page load since jquery hasn't loaded yet. You can use something like this
(function() {
function onLoad() {
// widget code
}
if (window.jQuery) {
onLoad();
} else {
window.addEventListener('DOMContentLoaded', onLoad);
}
})();