Home > front end >  How can i 'use' a js file from other js file in html even if its one line lower
How can i 'use' a js file from other js file in html even if its one line lower

Time:11-25

I know that using a function or a variable by file1 from file2 can't work:

<head>
<script src="file1.js"></script>
<script src="file2.js"></script>
</head>

Because file2 is 1 line lower than file2 but is there something that can make it possible? I don't want to use all of js script in one file or in html file because it would be a mess is there something i can do so it will work

I tried swapping file1 and file2 but it still gave me errors about functions and values being null and i don't know what to do

Some of problems can be solved if you read comments from the answer

CodePudding user response:

You don't "use" them in your HTML. you need to import one of them to the other, then you will have access to the other's values. for more information please follow the Link.

just a side note regarding your code. A. your script tags are wrong (should be <script src="file1"></script>) B. it's better to put your scripts at the bottom of your body element.

  • Related