Can't Find Variable: $

Can't Find Variable: $
var scriptFile = $(tempNode).attr("customJScriptSrc");

When passing this i get

“Reference Error: Can’t find variable: $”

Kindly suggest me any alternative methods.

4

2 Answers

add this script:

<script src=""></script>

at top of the document(added before your javascript code).

or download the library and reference it in you code.

2

I had this same problem and it was caused by me putting my .js file before the jQuery .js file in the DOM. This was causing an error because it was trying to read my .js file before recognizing that jQuery was even installed. Always put all your scripts in order of execution and alway at the very bottom of the body tag. This always makes sure that the page is fully loaded before trying to execute any javascript.

Before (Incorrect):

<script type="text/javascript" src="_javascript/rp-global.js"></script>
<script type="text/javascript" src="_javascript/jquery-3.2.1.min.js"></script>

After (Correct):

<script type="text/javascript" src="_javascript/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="_javascript/rp-global.js"></script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.