Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link external javascript file in Adobe Brackets IDE?

The code works in Codecademy but doesn't seem to work in Adobe Brackets IDE. Greatly appreciate any help on this issue!

HTML File

<!DOCTYPE html>
<html>
    <head>
        <title>Testing</title>
        <link type="text/css" rel="stylesheet" href="stylesheet.css">
    </head>

    <body>
        <div></div>
        <script src="script.js"></script>
    </body>
</html>

CSS File

div{
    height: 100px;
    width: 100px;
    background-color: aqua;
}

Javascript File

var main = function(){
    $('div').click(function(){
        $('div').hide();
    });
};

$(document).ready(main);
like image 772
Rafilson Avatar asked Jun 11 '15 04:06

Rafilson


People also ask

How do I link an external JavaScript code?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

How do I run a JavaScript file in Brackets?

How do you run JavaScript code in Brackets console – The console plus extension should be installed and then use the F9 shortcut key. In the Brackets, this extension is used to see the console. log and console.

Where is the external JavaScript file stored?

The file can be saved anywhere in the Web Project directory. It is common practice to put JavaScript files in a folder named "javascript" or "src" when building web and mobile applications.

How does external JavaScript work?

External JavaScript is when the JavaScript Code(script) is written in another file having an extension . js and then we link this file inside the <head> or<body> tag of our HTML file in which the code is to be added.

What is the default file extension for external JavaScript files?

External JavaScript JavaScript files have the file extension .js.


2 Answers

check your folder structure. there is nothing to do with the editor when you are including js files.

one more thing your code seems a jQuery code and to make it run you will need jQuery library file included before your script.js file. to use jQuery functions in your code you need to add the functions library first.

check code below

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
 <script src="script.js"></script>
like image 83
Nilesh Mahajan Avatar answered Sep 22 '22 10:09

Nilesh Mahajan


You've not included jQuery in your document.

http://jquery.com/download/

Via CDN:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

If you open your JavaScript console you'd likely see an error telling you that $ is not defined.

  • Chrome Developer Console
  • FireFox Developer Console
like image 28
Oka Avatar answered Sep 24 '22 10:09

Oka