1

I have js file and if I put <script src="link_to_file"></script> on bottom of my html page, it doesn't work.

Instead, if I put <script>function( etc..</script> on bottom of my html page, it works.

What is problem?

12
  • Check if file on link_to_file exists. Open in another tab to check. use inspect element to see the error Commented Jun 12, 2016 at 12:30
  • When you say it does not work? Have you viewed the element to see if the path even exists? Are you using a framework, wordpress or what? Commented Jun 12, 2016 at 12:32
  • @JurePotocnik link_to_file exits but isn't load.. Commented Jun 12, 2016 at 12:34
  • @Dan not working in <script src="link_to_file"></script> buy working on <script>function( etc..</script> Commented Jun 12, 2016 at 12:35
  • 1
    You can put your js in head and you can add a document ready function to it… this way DOM (html) is loaded before your script Commented Jun 12, 2016 at 12:38

2 Answers 2

1

Try this:

HTML

bottom

<script src="external-script.js><script>

EXTERNAL JS

Add $(document).ready(function () {})

  • Make sure jQuery is loaded first.

  • Check your global variables.

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure that you're using the right path, that's depending om your folder structure. For example, if the js file is in the same folder as your html file, use

<script src = 'fileName.js'></script>

Do not forget to include the .js extension at the end of the file name. The file name should be same as the name of your js file. Anyhow, you do not have to put the script in the head section as someone has suggested. It's in fact, not a good practice.

7 Comments

Are the files in the same folder or in separate folders?
It would really help if I could see your folder structure
In separate folders.. i fix it but i have a new problem, slider doesn't working.. i put all slider functions on js file but this functions doesn't working on page?
<script = '../folder/filename.js'></script>
Kindly post your code ... It will be much easier telling where the problem is. Post both the javascript and html code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.