Skip to content Skip to sidebar Skip to footer

I Can't Figure Out Why My Javascript File Won't Display When Linked

I can't figure out what's wrong here and I'm not getting any output from the Javascript file. I am trying to use src to be able to type my javascript file outside of the index file

Solution 1:

If the script is in the same folder as the HTML file, then you can just do:

<scriptsrc="slider.js"></script>

The starting / means "from the root", and the root might not be what you'd expect. Root does not mean the location of the HTML that loaded it, but the root of the file system or the domain.

Content must be placed inside the <body>, and not anywhere else. <head> is usually for scripts, styles, page metadata, but not the content.

Also, language can be omitted since <script> run JavaScript by default anyway.

Solution 2:

You're using HTML5 doctype, just use this and remove script language :

<scriptsrc="/slider.js"></script>

You should avoid document.write as it's not a reliable way to output data to your page. If you ever use it after the window has finished loading, it'll replace all the html contents with the new content.

<html><head><title> The title goes here </title><scriptsrc="/slider.js"></script></head><body><h2> A Test Heading (this goes in the body) </h2></body></html>

Solution 3:

<!DOCTYPE html><html><head><title>LOL UR CAT SUX</title><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=0"></head><body><h1>
LOL UR CAT STILL SUX
</h1><p>
LOL UR CAT STILL <i>REALLY</i> SUX
</p></body></html>

Post a Comment for "I Can't Figure Out Why My Javascript File Won't Display When Linked"