John Smith
John Smith

Reputation: 1

My HTML file wont connect to my javascript file, why?

So my header looks like this...

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Deschutes Pine</title>
    <link rel="stylesheet" href="Crew.css">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src = "/Script.js"></script>
    <link href='http://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

And my Javascript looks like this:

    /*jslint browser: true*/
    /*global $, jQuery*/
    $(document).ready(function () {
        $('.faces').hide();
     });

Ive already tried posting the js in script tags and it ran smooth , so the problem is its finding the way to my js file. Script.js is in the same folder so it's not that.

Upvotes: 0

Views: 52

Answers (2)

<script type="text/JavaScript" src="script.js"></SCRIPT>

use this one if you have your JS into any folder then you can use (/foldername/filename.js).

Upvotes: 0

MaKR
MaKR

Reputation: 1892

If they're both in the subfolder you'd want to drop the leading / before the script's name. The preceding / brings you to the document root. Read up on relative URI's to get a better understanding if this doesn't make sense.

Also for your JQuery include I'd suggest eliminating the http and just leave //code.jquery.com/jquery-1.9.1.min.js (or as I prefer //ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js). This will prevent errors when including from an https page without changing the URI to specify https.

Upvotes: 1

Related Questions