How do you link a JavaScript file in HTML?

6 Answers
1. Rajendra Kumar Vankadari, UI Developer @ Flipkart ex Sapient.
use a script tag.
<script type=’text/javascript’ src=’PATH OF FILE’></script>
This instructs browser that whatever (text) comes within this tag should be treated as a Javascript code rather than plain HTML. Hence it stores it in engine memory and executes it.
However browsers these days are smart enough will understand the text inside this tag as code even if type=”text/javascript” is not mentioned.
2. Eoin Healy, Website Developer (2009-present).
There are 2 ways to do this,
1) linking to a .js file <srcipt src=”ajavascriptfile.js”></script> (usually within the <head></head> tags
or 2) embeding the js code within the html file like this:
<script type=”text/javascript”>
your js code here
</script>
If you can be a bit more specific, I can tell you which is the best option for you.
3. Scott Warner.
You could put something like this in the <head>:
<script src=”FileName.js”></script>
4. Anonymous.
On the bottom of webpage add:
<script src=”directory/filename.js” type=”text/javascript”></script>
Always remember to add the JS file in the bottom. While loading the page, this will help. All the elements will be loaded first and then javascript will be loaded.
5. Bhavesh Nigam, Every hour, happy hour. life is wacky now.
<script src=”path/to/your/static/js/file”></script>
6. Mark Hay.
I don’t quite know what you’re asking. If you want to include a JS script in an HTML file, you do it like so:
<script src=”yourscript.js”></script>
Let us know if there is another way to insert JavaScript in your own opinion Lets discuss in the comment box
what help do you need Sarah
Help!! This stuff is hard for me! Honestly, my brain isn't analytical enough lol
Very helpful. Thanks for sharing. : )
Informative
This is really helpful for me. I found that JS is really challenging but your article helps me a lot
Such a simple but useful post. Even those not in the technical field can make use of it. Everyone of us who own a website at some point need to do it.
I m also a software developer I preferred ur site when I m confused in coding
I feel like I'm always gonna be confused with stuff like that but this post helped clarify some imbigious things. Thanks
Well, nice one, I am a copy paste developer , so for me all hints are welcome
Nice post!