tags:

views:

27

answers:

2

How do I tell me .HTML file to link the jquery .js file I downloaded?

<html>
    <head>
    </head>
    <body>
        <a href="#">Test</a>
    </body>
</html>

Also, this script for example, where would it go in my .HTML?

$(function(){
    $(".someClass").tipTip();
});
+1  A: 

Inside of the <head> is the defacto standard for <script src="file.js"></script> to go. It will be parsed first as a result, though. If you feel that there's too much overhead from scripts you can dump them before the end body tag so the HTML is parsed beforehand. The latter is not necessary usually, unless there's lots of code.

meder
Do I have to give it a type or something; similar to CSS files? Also where would I put that script I wrote up there? Under the script tag, but inside the head tag?
Serg
The type is usually implied as `text/javascript`. You don't have to really specify it. It's a personal preference thing. One could ideally use a vbscript but all browsers will recognize a script without a type as Javascript.
meder
+1  A: 

The standard template I use for including files in HTML is shown here:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">    
</head>
<body>

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

The main thing to take away is:

  • CSS should always be included before JavaScript
  • The jQuery source file should always be before your other JavaScript files.
  • JavaScript is included at the bottom of the body tag to optimize page loading speed (but some people still prefer to put JavaScript in the Head section.
  • Script tags are now assumed to be JavaScript (but you can always be specific and give it the type="text/javascript" attribute/value pair).
Moses