[Solved] How to put javascript in html file


Following can be a reason for your issue

  1. Invalid src path in the script tag
  2. Javascript might be disabled in your browser.
  3. You have a script error/exception that stopped entire page’s script execution.
  4. Maybe you have an Ajax request that won’t work if your open it as a local file protocol. e.g., file://

What can you do?
It is right time for you to know about and use your developer tools available in your favorite browser.

See if it shows 404 or some other error. Then update your SO question with the exact error message that you see. We would be happy to help.

Revised answer based on provided w3c link:
Now we know the exact problem.
You can not add that script tag to the head of the HTML. Because the elements that you refer in the script are not available at that time of execution. Move the script tag just before the end of body tag (all your carousal tags/elements should be present before the script tag) . Then It would work as expected.

If you still want that script tag to be in the head section, then you have to initialize your carousal/slider in DOM ready event or window.Onload event.

Still my earlier comment is relevant, because you can use developer tools in your browser to find out the exact error statement.

1

solved How to put javascript in html file