views:

38

answers:

1

I have a simple call to replace the contents of a <div> with those of another HTML file using the .load() function:

$('#content').show().load('01.html');

01.html is in the same folder as this page. But the function isn't being executed. Is there a problem with my code? Or is it that the .load() function won't work until it's being served?

In the latter case, what's a good way to go about testing it?

A: 

You'll need to do this instead:

$('#content').load('01.html', function() {
  $(this).show();
});

It will show the content after a successful load (under the presumption that content was hidden to start with).

Gert G
It still isn't working. Let's forget about showing and hiding; even when the div is already shown its contents are removed, but not replaced. My question was whether the script would work locally. Will it? And if so, is there anything special that 01.html should contain (or not contain)?
Isaac Lubow
Yes, it works locally. `01.html` should contain some HTML or text. This will be shown inside you content `container`. Make sure that your ID is correctly spelled. E.g. The ID `content` isn't spelled `Content`. IDs are case sensitive.
Gert G
Also, make sure you got `$(document).ready(function() { ... });` around the jQuery if you're defining it before the `content` element, or else it won't find the element.
Gert G
hi isaac did you check the wamp/xampp server running properly
Gobi
@Isaac Lubow - Is there anything else you need to know?
Gert G