ali
ali

Reputation: 37

How to add jQuery to website

I have a web application. In the head of site master, I write this line:

<script type="text/javascript" src="/scripts/jquery-1.4.1.min.js"></script>

and when I create project, the script file is added, but when I use $ function, I get undefined error.

What should I do?

Upvotes: 0

Views: 101

Answers (1)

user2118542
user2118542

Reputation:

This is what I (and almost every other developer) do:

enter image description here

<head runat="server">
<title></title>
<script src="Scripts/jquery-1.8.0.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        //write jquery code 


    });
 </script>
 </head>

Or alternatively you can directly refer your custom JS beneath the jQuery reference.

 <script src="Scripts/jquery-1.8.0.js" type="text/javascript"></script>
 <script src="Scripts/Your_Custom_JS.js" type="text/javascript"></script>

Side Note

This is the preferred way of writing code because you will segregate from UI layer and also, Chrome browser does not support inline debugging.

Upvotes: 2

Related Questions