0

So guys, I guess my question is quite understandable: I want to include an external jQuery file into my HTML. I tried many many ways, which I thought (and still think) were correct, but it doesn't seem to be so.

This is my code:

 <script type="text/javascript" src="js/jquery-1.5.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.9.js"></script> <script type="text/javascript" src="js/pinkmoon.js"></script> 

Where pinkmoon.js is the file that holds my jQuery.

6
  • what's the error? is the file inside js dir and named exactly pinkmoon.js? make sure that you have index.html/js/pinkmoon.js Commented Mar 16, 2011 at 22:46
  • Looks like a path issue. Try having them in the same directory as your HTML file (and delete js/s from the HTML file)? Commented Mar 16, 2011 at 22:47
  • Is there a directory named js/? Commented Mar 16, 2011 at 22:49
  • When opening the page source and clicking on the paths (links) they open and it shows me the jQuery/Javascript code, which means the paths are correct. Commented Mar 16, 2011 at 22:49
  • @Dugi in that case, it should be fine. What doesn't work? Commented Mar 16, 2011 at 22:50

2 Answers 2

5

If you navigated to a page that physically resides in a folder structure like so:

http://mywebsite.com/folder1/subfolder1/myPage.html

Then with your current code the source is going to look like this:

src="http://mywebsite.com/folder1/subfolder1/js/pinkmoon.js"

Which is not what you want. What you do want is this:

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

Which would infer that the physical location of pinkmoon.js resides at:

http://mywebsite.com/js/pinkmoon.js

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

5 Comments

As I said, once I open the page source, and found the js/pinkmoon.js and click on it, it opens a new code window with all my jQuery, which means I navigated in the right path.
@Dugi, so obviously however your referencing code is incorrect, thus not working. Do you have functions in there that you call within the page?
No, there are no Javascript functions that are being called by events (onclick etc.) just pure code that works with HTML attributes (mostly ids).
@Dugi, it's hard to tell without seeing the code. Is the code you want to run on page load wrapped in $(function(){ });?
I got it fixed in some way. Thanks for your help :D.
0

This should work. Be sure to have the file you want to include in a directory called "js" at the same level of you html file.

For exemple :

mysite/index.html mysite/js/pinkmoon.js 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.