Sike12
Sike12

Reputation: 1262

Using $ or the JQuery keyword in external JS File

Below is the content in my external js file. Please i only have one function in my js file and i am calling this function from one of .cshtml file during onload event.

 function startJs()
 {

    $("#tabs").tabs();
    getImages();
    var imgCount = 0;
    var imgArray = new Array();
 }

Running this code i get the error saying "$ is not referenced". I get the same "not referenced error if i use the keyword JQuery.

I also tried declaring the function like this but still getting the same message.

$(function () {
   $("#tabs").tabs();
});

How can i make the Jquery symbols work in external js files. I feel that i am missing something very simple here but i just can't figure out what i am missing. Please note i am making a call to this code from a file that has a reference to Jquery.

Anybody has any solution to this? Thanks in advance.

Upvotes: 1

Views: 233

Answers (1)

stackErr
stackErr

Reputation: 4170

Your HTML should look like this, note the order of the JS files:

<html>
<head>
    ...
    <script src="jquery.js"></script>
    <script src="yourCustomFile.js"></script>
</head>
<body>
...
</body>
</html>

Upvotes: 3

Related Questions