views:

89

answers:

3

Hi,

I have created a horizontal menu with 5 tab options using a ul and 5 li tags that is held inside a div

Below this area, I have also create a separate div (id="content1") that will be used to display the content html files based on the tab options selected.

What I am unsure how to accomplish using both JavaScript and jQuery, how can I through a onlick call, replace the div content1 with the html file content? Say I clicked the tab "features" - would like to replace div id content1 with features.html file content?

Any help would be great.

Thanks.

+3  A: 

This is easy to do using jQuery and load() to load the remote content and apply it to a div.

Lucky you, there's a great tutorial that explains exactly how to do this! :)

Alex
+1 That is my favorite Ajax tutorial :)
fudgey
Hi, even though I ticked this as my answer, I realised after actually attempting it, each menu option alone is a whole copy of all the web page but just for that menu option. I actually did not want to take this approach, even thought is it an excellent tute. I just want to replace the same content div alone and not render whole html page.
tonsils
Each html file is an entire copy of the page for backwards-compatibility so if javascript is disabled it will still open the correct page.If you look closely, the script only loads the "content" div of the html file and only replaces the "content" div of the current page, so its exactly what you need! :)
Alex
No worries Alex - appreciate the explanation. Thanks.
tonsils
Hi Alex, got everything working fine but when I centered my website, the unloading/loading always occurs from the left of the browser and not from my newly centered position. Any ideas? Thanks.
tonsils
what do you mean loading occurs from the left of the browser?? can you show a screenshot/demo? thanks!
Alex
A: 

Couldn't your retrieve the file contents via AJAX, and then set the contents of the div with .html()?

Matt Luongo
+1  A: 

Try something like this:

$("#features").click(function(){
   $("#content1").load('features.html');
});
Sarfraz