tags:

views:

91

answers:

3

<script type= "text/javascript">


   //<!CDATA[[

$(init);

function init() {
 $("#heading").load("head.html");
 $("#menu").load("menu.html");
 $("#content1").load("story.html");
 $("#content2").load("story2.html");
 $("#footer").load("footer.html");
};

  //]]>

</script>
+7  A: 

For some reason jQuery is not loading.

Check your path is it really src = "jquery-1.4.2.min.js" ? or could it be: src = "jquery/1.4.2.min.js"?

Make sure your jQuery is being loaded. Go to the source page and make sure you can read it. To debug use the full URL of the source instead of just a relative path. Then if that works, change it to a relative path and see if it still works.


Your first <script> tag is malformed:

This is malformed:

<script type= "text/javascript"
        src = "jquery-1.4.2.min.js"</script>


It should read:

<script type= "text/javascript"
        src = "jquery-1.4.2.min.js"></script>

(note the > right before the </)

A clue to the presence of this type of problem is often the lack of syntax highlighting in your IDE or editor. In fact note the difference in the Stack Overflow syntax highlighting between the two code snippets above.


Also CDATA should be

//<![CDATA[

and not:

//<!CDATA[[
Peter Ajtai
fixed but still says $ is not defined
@user 449914 - Check that the jquery is being loaded... try putting in the full url as the source after going to that url to make sure the file is actually there.
Peter Ajtai
I am running it locally, so it should be loading the jquery file..
@user449914 - It **should** be loading, but it's not **actually** loading. Initially using the full URL helps you debug. Can you see the jQuery code page by navigating there with your browser?
Peter Ajtai
dumb ass error...jquery file was in a different folder!! sorry and thanks!
@user44914 - You're welcome ;) Happens to everyone. It's just a game of patience. Don't forget to accept my answer if it solved your problem. (Green check mark below the vote count).
Peter Ajtai
A: 

Make sure you reference your jQuery.js file correctly, Test by adding an alert('HIT!'); in you jQuery file if you are unsure.

Once you have that sorted, do the following:

<script type= "text/javascript">

$(function(){
 $("#heading").load("head.html");
 $("#menu").load("menu.html");
 $("#content1").load("story.html");
 $("#content2").load("story2.html");
 $("#footer").load("footer.html");});

</script>

OR if you want to use your function,

function init() {
 $("#heading").load("head.html");
 $("#menu").load("menu.html");
 $("#content1").load("story.html");
 $("#content2").load("story2.html");
 $("#footer").load("footer.html");
};

And call the init() just before the closing body tag.

Marc Uberstein
A: 

Make sure you don't use jQuery.noConflict(), this removes the $ alias to avoid conflicts with other JavaScript libraries.

Adam Byrtek