title: jQuery Scroll to Anchor Within Div
body: <p>I'm trying to get it to where I can scroll #page to the anchor within the ajax response which is displayed withinin the #page div. The below code works for the first click, but not for subsequent clicks. What gives?  Thank you for your time...</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xlm:lang="en" lang="en"&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;
          &lt;title&gt;Example&lt;/title&gt;
   &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url(); ?&gt;resources/js/jqueryFileTree.css" media="all" /&gt;
  
   &lt;script type="text/javascript" src="&lt;?php echo base_url(); ?&gt;resources/js/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
   &lt;script type="text/javascript" src="&lt;?php echo base_url(); ?&gt;resources/js/jqueryFileTree.js"&gt;&lt;/script&gt;
  
  
  
   &lt;script type="text/javascript"&gt;
       $(document).ready(function() {
  
    $("#tree").fileTree(
        {root: 'county_code/',
        script: 'welcome/get_code',
        expandSpeed: 250,
        collapseSpeed: 250
        },
  
        function(file) {
     var split = file.split('/');
     var anchor = '#x' + split[split.length-1];
     var last_chapter = split[split.length-2];
     if ($("#last_chapter").html() != last_chapter) {
         $("#page").html('Loading...');
         $.ajax({
      type: 'post',
      url: 'welcome/get_page',
      data: {page: file},
      success: function(resp) {
          $("#page").html(resp);
          $("#page").prepend('&lt;div id="last_chapter"&gt;' + last_chapter + '&lt;/div&gt;');
  
          anchor = anchor.replace(".", "");
          console.log($("#page").offset().top);
          console.log($(anchor).offset().top);
          var scrollTo = $(anchor).offset().top - $("#page").offset().top;
          console.log(scrollTo);
          $("#page").animate({scrollTop: scrollTo}, "slow");
      }
         });
     } else {
         var split = file.split('/');
         var anchor = '#x' + split[split.length-1];
         anchor = anchor.replace(".", "");
         console.log($("#page").offset().top);
         console.log($(anchor).offset().top);
         var scrollTo = $(anchor).offset().top + 246;
         console.log(scrollTo);
         $("#page").animate({scrollTop: scrollTo}, "slow");
     }
  
        });
       });
          &lt;/script&gt;
  
   &lt;style type="text/css"&gt;
          body {
    background-color: #fff;
    margin: 40px;
    font-family: Lucida Grande, Verdana, Sans-serif;
    font-size: 12px;
    color: #4F5155;
   }
   img.loading {
       display: block;
       margin-left: auto;
       margin-right: auto;
       margin-top: 150px;
   }
   a {
    color: #003399;
    background-color: transparent;
    font-weight: normal;
   }
  
   h1 {
    color: #444;
    background-color: transparent;
    border-bottom: 1px solid #D0D0D0;
    font-size: 16px;
    font-weight: bold;
    margin: 24px 0 2px 0;
    padding: 5px 0 6px 0;
   }
   h2 {
    color: #444;
    background-color: transparent;
    font-size: 14px;
    font-weight: bold;
    margin: 10px 0 2px 0;
    padding: 5px 0 6px 0;
    text-align: center;
   }
   h3 {
    color: #444;
    background-color: transparent;
    font-size: 12px;
    font-weight: bold;
    margin: 20px 0 2px 0;
    padding: 5px 0 6px 0;
    text-align: center;
    text-transform: uppercase;
    text-decoration: underline;
   }
   p.section_title span {
       padding-right: 10px;
   }
   p.section_title {
       margin-bottom: 0;
   }
   li {
       padding: 4px 0;
   }
   ol {
       margin-top: 0;
       padding-top: 0;
  }
   ol ol {
       list-style-type: lower-alpha;
   }
  
   p {
       padding: 5px;
   }
  
   #tree {
       width: 45%;
       float: left;
       margin: 5px;
       border: 1px solid #545454;
       height: 600px;
       overflow: auto;
   }
   #page {
       width: 45%;
       float: left;
       margin: 5px;
       border: 1px solid #545454;
       height: 590px;
       padding: 5px;
       overflow: auto;
   }
   .clear {
       clear: both;
   }
      &lt;/style&gt;
      &lt;/head&gt;
      &lt;body&gt;
  &lt;h1&gt;Demo&lt;/h1&gt;
  
  &lt;p&gt;Below you will find a table of contents and the code itself. It is not official, blah blah blah.&lt;/p&gt;
  
  &lt;div id="tree"&gt;&lt;/div&gt;
  
  &lt;div id="page"&gt;
      &lt;p&gt;This would be the page content.&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;br class="clear" /&gt;
  
  &lt;p&gt;&lt;br /&gt;Page rendered in {elapsed_time} seconds&lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The ajax response (just a sample...):</p>
  
  <pre><code>&lt;h2&gt;Chapter 1&lt;/h2&gt;
      &lt;h3&gt;General Provisions&lt;/h3&gt;
      &lt;p id="x1010" class="section_title"&gt;
      &lt;span&gt;1.010&lt;/span&gt; &lt;u&gt;County Code: Title; citation; reference.&lt;/u&gt;
      &lt;/p&gt;
      &lt;ol&gt;
      &lt;li&gt;This code shall be known as the County Code, and it is sufficient to:
          &lt;ol&gt;
          &lt;li&gt;Refer to the code as the County Code in any prosecution for the violation of any provision thereof or in any legal proceeding.&lt;/li&gt;
          &lt;li&gt;Designate any ordinance adding to, amending, correcting or repealing all or any part or portion thereof as an addition to, amendment to, correction or repeal of the County Code.&lt;/li&gt;
          &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
          Further reference may be had to the chapters, sections and subsections of the County Code, and such references shall apply to that numbered chapter, section or subsection as it appears in the code.
      &lt;/li&gt;
      &lt;/ol&gt;
  
      &lt;p id="x1020" class="section_title"&gt;
      &lt;span&gt;1.020&lt;/span&gt; &lt;u&gt;Definitions.&lt;/u&gt; As used in the County Code, unless the context otherwise requires, the words and terms defined in sections 1.030 to 1.180, inclusive, have the
      meanins ascribed to them in those sections.
      &lt;/p&gt;
  
      &lt;p id="x1030" class="section_title"&gt;
      &lt;span&gt;1.030&lt;/span&gt; &lt;u&gt;"Board of county commissioners" defined.&lt;/u&gt; "Board of county commissioners" means the board of county commissioners of County, State.
      &lt;/p&gt;
  
      &lt;p id="x1040" class="section_title"&gt;
      &lt;span&gt;1.040&lt;/span&gt; &lt;u&gt;"County" defined.&lt;/u&gt; "County" means County, State.
      &lt;/p&gt;
  
      &lt;p id="x1050" class="section_title"&gt;
      &lt;span&gt;1.050&lt;/span&gt; &lt;u&gt;"County commissioners" defined.&lt;/u&gt; "County commissioners" means the board of county commissioners of County, State.
      &lt;/p&gt;
  
      &lt;p id="x1060" class="section_title"&gt;
      &lt;span&gt;1.060&lt;/span&gt; &lt;u&gt;"District health department" defined.&lt;/u&gt; "District health department" means the district health department of County, State.
      &lt;/p&gt;
  
      &lt;p id="x1070" class="section_title"&gt;
      &lt;span&gt;1.070&lt;/span&gt; &lt;u&gt;"District health officer" defined.&lt;/u&gt; "District health officer" means the executive officer of the district health department.
      &lt;/p&gt;
  
      &lt;p id="x1080" class="section_title"&gt;
      &lt;span&gt;1.080&lt;/span&gt; &lt;u&gt;"Intoxicating liquor" defined.&lt;/u&gt;
      &lt;/p&gt;
      &lt;ol&gt;
      &lt;li&gt;"Intoxicating liquor" means beer, wine, gin, whiskey, cordials, ethyl alcohol or rum, and every liquid or solid, patented or not, containing one-half of 1 percent
          or more of alcohol by volume and which is used for beverage purposes.&lt;/li&gt;
      &lt;li&gt;"Intoxicating liquor" is synonymous with "alcoholic beverage."&lt;/li&gt;
      &lt;/ol&gt;
  
      &lt;p id="x1090" class="section_title"&gt;
      &lt;span&gt;1.090&lt;/span&gt; &lt;u&gt;"May" defined.&lt;/u&gt; "May is permissive.
      &lt;/p&gt;
  
      &lt;p id="x1100" class="section_title"&gt;
      &lt;span&gt;1.100&lt;/span&gt; &lt;u&gt;"Month" defined.&lt;/u&gt; "Month" means a calendar month unless otherwise expressed.
      &lt;/p&gt;
  
      &lt;p id="x1110" class="section_title"&gt;
      &lt;span&gt;1.110&lt;/span&gt; &lt;u&gt;"Must" defined.&lt;/u&gt; "Must" is mandatory.
      &lt;/p&gt;
  
      &lt;p id="x1120" class="section_title"&gt;
      &lt;span&gt;1.120&lt;/span&gt; &lt;u&gt;"Oath" defined.&lt;/u&gt; "Oath" includes an affirmation or declaration in all cases in which, by law, an affirmation may be substituted
      for an oath, and in such cases "swear" and "sworn" shall be equivalent to "affirm" and "affirmed."
      &lt;/p&gt;
  
      &lt;p id="x1130" class="section_title"&gt;
      &lt;span&gt;1.130&lt;/span&gt; &lt;u&gt;"Person" defined.&lt;/u&gt; "Person" includes a company, partnership, association or corporation as well as a natural person.
      &lt;/p&gt;
  
      &lt;p id="x1140" class="section_title"&gt;
      &lt;span&gt;1.140&lt;/span&gt; &lt;u&gt;"Planning commission" defined.&lt;/u&gt; "Planning commission" means the regional planning commission created by chapter 110 of the County Code or any successor
      planning commission legally created to perform the functions of planning for County.
      &lt;/p&gt;
  
      &lt;p id="x1150" class="section_title"&gt;
      &lt;span&gt;1.150&lt;/span&gt; &lt;u&gt;"Shall" defined.&lt;/u&gt; "Shall" is mandatory.
      &lt;/p&gt;
  
      &lt;p id="x1160" class="section_title"&gt;
      &lt;span&gt;1.160&lt;/span&gt; &lt;u&gt;"Sheriff" defined.&lt;/u&gt; "Sheriff" means the sheriff of County or in the case of his absence or inability to discharge the powers and duties of his office, then the person
      next in command of the County sheriff's department.
      &lt;/p&gt;
  
      &lt;p id="x1170" class="section_title"&gt;
      &lt;span&gt;1.170&lt;/span&gt; &lt;u&gt;"State" defined.&lt;/u&gt; "State" means the State of State.
      &lt;/p&gt;
  
      &lt;p id="x1180" class="section_title"&gt;
      &lt;span&gt;1.180&lt;/span&gt; &lt;u&gt;"Year" defined.&lt;/u&gt; "Year" means a calendar year.
      &lt;/p&gt;
  
      &lt;p id="x1190" class="section_title"&gt;
      &lt;span&gt;1.190&lt;/span&gt; &lt;u&gt;Construction.&lt;/u&gt;
      &lt;/p&gt;
      &lt;ol&gt;
      &lt;li&gt;The provisions of the  County Code are to be construed with a view to effect its objects and to promote justice.&lt;/li&gt;
      &lt;li&gt;All provisions of the  County Code shall be considered to speak as of the same date, except that in cases of conflict between
          two or more provisions, or of any ambiguity in a provision, reference may be had to the ordinances from which the provisions are derived
          for the purpose of applying the rules of construction relating to repeal or amendment by implication, or for the purpose of resolving the ambiguity.&lt;/li&gt;
      &lt;li&gt;The provisions of the  County Code shall be considered as substituted in a continuing way for the prior ordinances repealed by section 2 of the ordinance
          enacting this code.&lt;/li&gt;
      &lt;li&gt;The various analyses contained in the  County Code, constituting enumerations or lists of chapters and sections of the  County Code, and the
          descriptive headins or catchlines immediately preceding or within the texts of individual sections, except the section numbers included in the headings or
          catchlines immediately preceding the texts of such sections, do not constitute part of the law.&lt;/li&gt;
      &lt;li&gt;Whenever any reference is made to any portion of the  County Code or of any law of the State of State or the United States, such reference
          shall apply to all amendments and additions thereto now or hereafter made.&lt;/li&gt;
      &lt;/ol&gt;
  </code></pre>