Saturday, February 22, 2014

JavaScript include not working

The other day I was trying to include a JavaScript file in my HTML page, and I could not get it to work. I read several  posts about how to do it.  I was sure the path and syntax in the tag were right.  I had:

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


 The page would still not recognize the functions in the file.  Well, turns out I didn't have the syntax exactly right.  Above, I was using the shorthand syntax for closing an empty tag.  I figured that since there was no content for the script tag itself, I could close it the short way.  Apparently, it is not allowed to use the short notation for closing the script tag.  After I changed to the code below, everything worked great!

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

Once I found the solution (probably in a comment on Stack Overflow, I don't remember), then I found a whole article on the subject at Stack Overflow.

No comments:

Post a Comment