Skip to content
Advertisement

How to place Javascript in a separate file from HTML

I have this code placed in index.html, all together – Javascript and HTML. what I want is to place the JS into another, separate file called “pw.js”.

I have created a blank JS file located in folder “js”. I have added it to (head) as well like this <script src="js/pw.js"></script>

This is what I have now in index.html, how to place the JS separatly? Please be specific in answers, I’m a beginner.

JavaScript

Advertisement

Answer

your pw.js file in js folder:

JavaScript

your html file:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement