Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8099107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:17:41+00:00 2026-06-05T22:17:41+00:00

Trying to load content into a div, then on click load the previous content

  • 0

Trying to load content into a div, then on click load the previous content that was in the div again.

This is the code I have so far:

$(document).ready(function(){
   var mainClone = null;
   $('.project').click(function(e){
      var link = $(this).attr('rel');
      event.preventDefault();
      var mainClone = $('#main').clone();
      $('#main').load(link);
   });      

  $('.back').click(function(e){
  event.preventDefault();
  $('#main').load('mainClone *');
  });
});

What am I doing wrong? This is driving me nuts!

On a side note, is this a good solution to my problem?
I’m trying to achieve something similar to the work section on: http://www.revolver-studio.com/
You click a thumb and it goes into more info then you click back to go to the thumbs again.
ANY help would be really appreciated.
Thanks guys!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:17:43+00:00Added an answer on June 5, 2026 at 10:17 pm

    Several problems.

    First is the second use of var mainClone within project click handler. This is declaring a new variable named mainClone and is not the same as the original one you declared. The new one only has scope within the function it is declared in, so the original more global one will never change.

    Next problem us use of load() when you want to replvce the html with the stored html. It is both inappropriate for what you want to do and the argument is simply a string which is invalid.

    $(document).ready(function(){
       var mainClone = null;
       $('.project').click(function(e){
          var link = $(this).attr('rel');
          event.preventDefault();
          /*var mainClone = $('#main').clone();*/ 
          mainClone = $('#main').html();// now will update var declared above and only get the html within the element
          $('#main').load(link);
       });      
    
      $('.back').click(function(e){
      event.preventDefault();
      if( mainClone ){ // make sure it's not null still
        $('#main').html( mainClone);
      }
      });
    });
    

    Overall this code will still be a little weak but it is not intention of SO to build an app for you. It should get you started

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use this with tabs that load content with ajax into a
I use this code to load the content from a different page into the
I'm trying to load in AJAX content into an empty but the div won't
So I'm trying to load dynamic content straight into my checkbox container (group_checkboxes) <div
I'm trying to load page content into a div via Ajax when a select
Im trying to load content into a DIV from an XML file when the
I'm trying to load content from another page div into another page div. What
All, I'm trying to load some content into a fancybox. I'd like to load
I'm trying something very simple. Upon page load the data in content div is
I am trying to load just the contents of a <div> into another <div>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.