jQuery newb and the first poster. Please be careful :-) I searched and cannot find the answer, but I'm sure there is a really simple solution.
Hope someone can help me. Here's what I'm trying to achieve: I have a number of tabs, and all but the first tab use the click function to load () the external page into the required div. The first tab will load the default content, not from an external file, but from the div already on the page, but further down the code for SEO reasons.
Clicking on any other tab loads the content from the external page into the div, but if you want to return to tab 1, the content is not available, since it was replaced by the contents from load (), that is, it was no longer in the DOM.
I suppose I could add a div to #temp before calling load (), and then add it back if link 1 was clicked, but should there be a more elegant solution?
Here is the code:
$(document).ready(function(){ // default tab1 content div appended to containing div OK $("#innerDiv1").appendTo("#outerDiv"); // tab2 link loads page2.html OK $("#link2").click(function(){ $("#outerDiv").load("page2.html"); }); // This doesn't work as it no longer in the DOM after #link2 clicked. $("#link1").click(function(){ $("#innerDiv1").appendTo("#outerDiv"); }); });
Any thoughts and answers were greatly appreciated.
Thanks in advance M
source share