Trying to move javascript from .html to seperate .js so as to tidy up .html page

Viewed 40

enter image description here enter image description here

How can i move the large amount of to a seperate .js I understand that the script containing the src must be there but cant seem to move the other large chunk . Usually I can have all my webpages with seperate .html, .js and .css files as i find it tidier

1 Answers

If you are trying to move javascript code to a separate file just copy and past it into a '.js' file. Then, save it somewhere in the hierarchy of your code base. Such as:

myapp/js/main.js

Then, link it to your page. For example if my index.html file is within myapp like this:

myapp/index.html

You would put:

<script src="/js/main.js" type="text/javascript"></script>

If this is not what you asking please be more specific when asking a question. Are you asking about moving all code centrally? Do you want the code to be separated into respected directories to organize it?

It may also help us to see what the directory structure is for you application.

I saw your comment. Make sure your framework you are using is above your separated js file

Related