Jquery runtime div's not printing properly
<p>The code below is supposed to grab the news feed from a json object and print the news one below each other in a stacked format like this </p>

<p>2013
 - 1
   - News 1
   - News 2
 - 2 
   - News 1
   - News 2
2012
 - 1
   - News 1
   - News 2
 - 2 
   - News 1
   - News 2</p>

<p>Here is my feed</p>

<pre><code>    {
  "currentYear": "2013",
  "data": [
    {
      "id": "33",
      "year": "2012",
      "month": "3",
      "day": "25",
      "sourcename": "WSF",
      "title": "Test",
      "url": "www.test.com",
      "ingress": "data"
    },
    {
      "id": "72",
      "year": "2012",
      "month": "1",
      "day": "20",
      "sourcename": "SF times",
      "title": "Test 1 ",
      "url": "www.gogole.com",
      "ingress": "data"
    }
  ]
}
</code></pre>

<p>here is my jquery </p>

<pre><code>var date = new Date();
var currentYear = date.getFullYear();
var id;
var div_year_id;
var div_month_id;
var tmp_div_year_id;
var i = 1;


$.each(feed.data, function(key, val){

    if(tmp_div_year_id != "#" + val.year) {
        div_year_id     = "#" + val.year;
        div_month_id    = "#" + val.year + "_" + val.month;
    }

    //check if the div for the year exists
    if($(div_year_id).length &gt; 0) {
        console.log("adding year");
        // check if the div for the month exists
        if($(div_month_id).length &gt; 0) {
            console.log("adding month")
            // append to the div year id
        } else {
            //create the month id
            $(div_year_id).append('&lt;div id='+ div_month_id + '&gt;&lt;/div&gt;');
        }
    } else {
        //create the year id
        $("#news").append('&lt;div id='+ div_year_id + '&gt;&lt;div id='+ div_month_id +'&gt;&lt;h1&gt;' + val.title + '&lt;/h1&gt;&lt;p&gt;&lt;em&gt;Date&lt;/em&gt;: '+ val.year + '-' + val.month + '-' + val.day +'&lt;/p&gt;&lt;p&gt;' + val.ingress +'&lt;/p&gt;&lt;p&gt;&lt;em&gt;Source&lt;/em&gt;: '+ val.sourcename + '&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="'+ val.url +'" target="_blank"&gt;Read full article &gt;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;');
        $(div_year_id).append('&lt;div id='+ div_month_id + '&gt;&lt;/div&gt;');

        tmp_div_year_id = div_year_id;
    }
    console.log(tmp_div_year_id);
    i++;
});
</code></pre>

<p>the code is not stacking the news properly in one div for each year it creates a new div for each year</p>
