Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery fix for "Uncaught TypeError: $ is not a function" error [duplicate]

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.

like image 676
michaelmcgurk Avatar asked Oct 22 '15 10:10

michaelmcgurk


People also ask

How do I fix uncaught TypeError is not a function?

The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.

How do I fix uncaught ReferenceError jQuery is not defined?

Answer: Execute Code after jQuery Library has Loaded The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.

Is not a function error jQuery?

on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.

Is not a function TypeError?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.


1 Answers

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.

like image 149
Domain Avatar answered Oct 20 '22 04:10

Domain