title: On click go to page and execute a function
body: <p>I have a page with multiple elements (page A). It is set up, so all are hidden but one. When you click on a link it will hide the one currently shown and only show the section corresponding to the link you clicked. I have that code working perfectly. I also have a separate page (page B) that has a list of links. When you click one of these links, I would like to load the page with multiple elements (page A) and show the element corresponding with the link clicked on the previous page. Below is the code I have as of now. It loads the page perfectly, but it doesn't show the appropriate element (I think because maybe that element does not exist when the code is run because the page is still loading?).</p>
  
  <pre><code>$(function() {
    $('li').click(function(){ //link that is clicked on
      var currentId = $(this).attr('id'); //capture id of clicked item
      window.location = 'next-page.php'; //load new page
      $('#all-elements').fadeOut(0); //hide all elements
      $('currentId').fadeIn("slow"); //show only corresponding element
      return false;
    });
  });
  </code></pre>
  
  <p>I have set it up so the list item on the first page and the element I would like to show have the same id. My thinking in this is that I could capture the current id and use that value in the function as I do above. I know my problem is similar to the problem <a href="https://stackoverflow.com/questions/1184648/onclick-go-to-url-then-do-something-specific">found here</a>, but I don't think the # technique will work for what I am doing.</p>