Linking javascript to html


#1


Replace this line with your code.


#2

Hi @bradcandy,

Do you need help?


#3

Yes I do. I am understanding the begining course subjects for html and css and also think I understand the java script code of making the text into bubbles and having them move and I want to take that javascript and put it into an html file I already have going. I want to know how to link the javascript to html. I also would like to know what code editor would be best for a newbie. I see the format of the courses of codecademy are in and I find that very simple to use but I can't figur out how to use different code editors the same way.


#4

@bradcandy You can link JavaScript and HTML by adding a <script> tag just before </body> in the HTML file, with a src attribute pointing to the JS file. For example, if your JS file is named script.js and in the same directory as the HTML file, you would do this:

<script src="script.js"></script>

I also would like to know what code editor would be best for a newbie

Whichever one comes native on your system is what I'd recommend. Once you feel comfortable with that and decide you'd like to explore options, take a look at Visual Studio Code, Brackets, Atom, or Notepad++ [Windows only]


#5

I a stuck on a code editor. I am using Brackets but live preview will not preview. I keep getting the attached error.


#6

@bradcandy Have you tried renaming your HTML file to index.html, like the error says?


#7

Yes. Still getting the same message. Even with the default index.html that came with brackets


#8

@bradcandy In that case, I think the easiest thing for you to do would be to open the file directly in the browser (double-click on it from your file manager), and manually refresh each time you make a change.


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.