jQuery fix for “Uncaught TypeError: $ is not a fun

2019-02-05 04:27发布

This question already has an answer here:

My code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>      
<script src="http://someothersite.com/external.js"></script>

external.js:

$("head").append(unescape(""));

Unfortunately I am getting the following error when I include my external script:

Uncaught TypeError: $ is not a function

How do I fix this? Please bear in mind I can't edit the external Javascript file as it's third party.

3条回答
▲ chillily
2楼-- · 2019-02-05 05:08

I think the issue was because the external javascript was loaded first before the jquery was loaded. To solve this use requirejs, follow this link for the usage http://requirejs.org/docs/api.html

查看更多
老娘就宠你
3楼-- · 2019-02-05 05:23

Use the following statement in a JS file.

jQuery(document).ready(function($){

// jQuery code is in here

});

After declaring the above statement you will be able to use $ sign.

查看更多
相关推荐>>
4楼-- · 2019-02-05 05:23

It was using an old version of jQuery.

I updated the version and this resolved the issue for me.

Woop!

查看更多
登录 后发表回答