How to link external javascript file in Adobe Brackets IDE?
Asked Answered
D

2

6

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);
Doghouse answered 11/6, 2015 at 4:29 Comment(0)
B
1

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>
Burnaby answered 11/6, 2015 at 4:40 Comment(4)
Finally managed to get the code working! Thanks for your help!Doghouse
@RafflesAndrison: if you my answer is useful to you, you can accept it by ticking correct markBurnaby
How to refer internal js file, I added the script tag in the header, the file is not loaded in the browser, How to fix thisBuffy
@Buffy Can you show your code? without looking at what code you have, it is very hard to help you.Burnaby
G
1

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.

Georginageorgine answered 11/6, 2015 at 4:38 Comment(0)
B
1

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>
Burnaby answered 11/6, 2015 at 4:40 Comment(4)
Finally managed to get the code working! Thanks for your help!Doghouse
@RafflesAndrison: if you my answer is useful to you, you can accept it by ticking correct markBurnaby
How to refer internal js file, I added the script tag in the header, the file is not loaded in the browser, How to fix thisBuffy
@Buffy Can you show your code? without looking at what code you have, it is very hard to help you.Burnaby

© 2022 - 2024 — McMap. All rights reserved.