title: Pass variable to append
body: <p>On the homepage, the JS will grab up to three news stories from the news page, and will show abbreviated versions which will link to full story. The problem I'm running into is that one of the variables I'm attempting to concatenate is not doing so as intended.</p>
  
  <p>Homepage:</p>
  
  <pre><code>&lt;div id="news-autoloader"&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Newspage:</p>
  
  <pre><code>&lt;h3 id="news1"&gt;News Item 1&lt;/h3&gt;
  
  &lt;p&gt;Lorem ipsum dolor sit amet...&lt;/p&gt;
  
  &lt;h3 id="news2"&gt;News Item 2&lt;/h3&gt;
  
  &lt;p&gt;Lorem ipsum dolor sit amet...&lt;/p&gt;
  
  // more or less of the same news items
  </code></pre>
  
  <p>The news page may have no items, but we will capture up to three, first the headline, and then n characters (would rather capture n words, but that's after this issue is resolved!) of the first p following the h3 headline.</p>
  
  <pre><code>&lt;script&gt;
  $.get('company-news.html',
      function(data){
          var news1 = $(data).find('#news1 + p');
          var news2 = $(data).find('#news2 + p');
          var news3 = $(data).find('#news3 + p');
  
  // see how many news items there are (there's probably a more graceful way of doing this!):
  
      if (news1.html() == null){
          var items = 0;
      } else if (news2.html() == null){
          var items = 1;
      } else if (news3.html() == null){
          var items = 2;
      } else {
          var items = 3;
      }
  
      if (items == 0){
          $('#news-autoloader').append('&lt;h3&gt;No News.&lt;/h3&gt;');
      } else {
          for (i=1; i&lt;=items; i++){
              var abc = '#news' + i;
              var def = 'news' + i;
              var url   = 'a href="company-news.html#news' +i;
  
              $('#news-autoloader').append($(abc,data)).append('&lt;p&gt;' + def.html().substr(0, 175) + ' &lt;' + url + '"&gt;More&lt;/a&gt;&lt;/p&gt;');
          }
      }
  }, 'html');
  &lt;/script&gt;
  </code></pre>
  
  <p>Everything works - <code>abc</code> evaluates properly in the first append, but in our second append, variable <code>def</code> does not.</p>
  
  <p>I would like to know three things:</p>
  
  <p>1) How do I get <code>def</code> to work in the second append,</p>
  
  <p>2) Is there a more graceful way find the number of news items,</p>
  
  <p>3) How do I limit by number of words instead of characters (so abbreviated sentences are complete).</p>
  
  <p>TIA!!!</p>