title: delete last accordion with jquery
body: <p>I can add an accordian with jQuery. But now I want also to delete the last selected accordian. I have it like this:
  HTML:</p>
  
  <pre><code>&lt;div class="span12" id="delete-contact"&gt;
      &lt;p style="text-align: center;"&gt;
          &lt;a href="#"&gt;Klik hier om contactpersoon te verwijderen&lt;/a&gt;
      &lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>$('#delete-contact p a').click(function() {
      $(this).parents('.panel').get(0).remove();
  });
  </code></pre>
  
  <p>But this doesn't work</p>
  
  <p>This is the html:</p>
  
  <pre><code> &lt;div class="span12" id="add-contact"&gt;
            &lt;p style="text-align: center;"&gt;
              &lt;a href="#"&gt;Klik hier om nog een contactpersoon toe te voegen&lt;/a&gt;
            &lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="span12" id="delete-contact"&gt;
            &lt;p style="text-align: center;"&gt;
              &lt;a href="#"&gt;Klik hier om contactpersoon te verwijderen&lt;/a&gt;
            &lt;/p&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>And this is for add and delete accordian:</p>
  
  <pre><code>// Add extra contact clicked?
                                  $('#add-contact p a').click(function()
                                  {
                                      // Make a copy of the first input fields
                                      html = $('#new-contact').children().clone();
  
                          // Get number of tabs in the accordion
                          var index = $('#accordion h3').length;
  
  
  
                      if(index == 0 )
  {
                           alert($('#accordion h3').length);
                          $('#contactpersonen_canorder_0').prop('checked', true);
                          $('#contactpersonen_canseestock_0').prop('checked', true);
                          $('#contactpersonen_canseeorders_0').prop('checked', true);
                          $('#contactpersonen_canaddaddress_0').prop('checked', true);
                          $('#contactpersonen_canseeprice_0').prop('checked', true);
                          $('#contactpersonen_canseecredit_0').prop('checked', true);
                          $('#contactpersonen_canseepickup_0').prop('checked', true);
  
  }               
  
  
                                      // Remove the values
                                      html.find("input[type=text]").val("");
                    html.find('input[type=checkbox]').attr('checked', false);
  
                          // New 'id', 'for' and 'name' attribute names
                          html.find('input[type=checkbox]').each(function () {
                              me = $(this);
                              attr = me.attr('id');
                              number = attr.split('_')[2];
                              newNumber = parseInt(index) + 1;
                              newAttr = attr.replace(number, newNumber);
                              me.attr('id', newAttr).attr('name', newAttr).next().attr('for', newAttr);
                          });                  
  
                                      // Insert it at the end
                          $('#accordion').append(html);
                          $('#accordion').accordion('refresh');
  
                          // Set last tab to active
                          $("#accordion").accordion({ active: index });
  
                                      // Cancel the click
                                      return false;
                                  });
  
  
                              $('#delete-contact p a').click(function(event)
                                  {
                                          event.preventDefault();
      $(this).parents('.panel').eq(0).remove();
            //$("#accordion).accordion("destroy");    // Removes the accordion bits
           //$("#accordion").empty();  
  
  
  
                                      });
  </code></pre>
  
  <p>If I do this:</p>
  
  <pre><code>$('#delete-contact p a').click(function(event)
                                  {
                                          event.preventDefault();
      //$(this).parents('.panel').eq(0).remove();
           // $("#accordion).accordion("destroy");    // Removes the accordion bits
           $("#accordion").empty();      
  
  
                                      });
  </code></pre>
  
  <p>Then all the accordians will be deleted. So for example I have two accordians and the last one - two have to be deleted. But now both will be deleted.</p>
  
  <p>I try it like this:</p>
  
  <pre><code>$('#delete-contact p a').click(function(event)
                                  {
                                          event.preventDefault();
      //$(this).parents('.panel').eq(0).remove();
          // $("#accordion).accordion("destroy");    // Removes the accordion bits
           $("#accordion").empty({ active: index });  
  </code></pre>
  
  <p>But now neither accordian will be deleted</p>
  
  <pre><code>            });
  </code></pre>