Hi everyone.
I have been recently starting a new project outside of fcc / codepen / etc. and was wondering how I go about ‘importing’ as such my html file into the js file? I have done this recently and I do know it involves import ...something...
in the .js file, but cannot recall exactly what.
I hope this makes sense, and am hoping I can get some help on this.
Thanks,
Boris
For simple front-end projects, you’d usually do this the other way around (link to the .js
file from your .html
file. You do that like this:
<script src="./path/to/javascript/file.js">
For example, in a flat directory structure like this:
project-dir
|–index.html
|–script.js
|–style.css
Your HTML would contain this:
<script src="./script.js">
You can import other JavaScript modules into a JavaScript file using import
, but that’s not supported by all browsers by default yet. It’s not used for importing HTML files.
ok, so as long as I link into the html file, using the script
tag, I don’t need to import anything into the js file, unless I was to import another js file??
Correct.
If you’re still confused, try googling HTML JS CSS boilerplate hello world
or similar.
Ok cool! Thankyou for your help!!