title: Select last generated tab by this function , jQuery Ui Tabs
body: <p>I have this function to generate JQuery UI Tabs . I want to modify it as when the last tab is generated, set it as a opened tab, please help me .. I fully mixed up ... Thanks </p>
  
  <pre><code>function addTab(title,content,Refrence) {
              $("#tabs").show();
                          $("#tabs").tabs();
              var btnCloseTab = document.createElement('span');
              $(btnCloseTab).addClass('ui-icon ui-icon-close');
              $(btnCloseTab).attr('role', 'presentation');
              $(btnCloseTab).click(function () {
                  $(this).parent().remove();
                  var contentId = $(this).parent().find('a').attr('href');
                  var contentIndex = contentId.substring(contentId.indexOf('-') + 1);
                  for (var i = 0; i &lt;= tabRefrenceArray.length; i++) {
                      if (Refrence == tabRefrenceArray[i]) {
                          tabRefrenceArray.splice(i, 1);
                      }
                      $(contentId).remove();
                  }
              });
              var tabIndex = 1;
              if ($('#ulTab li:last').length &gt; 0) {
                  var liId = $('ul li a:last').attr('id');
                  tabIndex = parseInt(liId.substring(2)) + 1;
              }
              var tabHeader = $('&lt;li id="li-'+tabIndex+'" class="liTab"&gt;&lt;a id="A-' + tabIndex + '" href="#tabs-' + tabIndex + '"&gt;' + title + '&lt;/a&gt;');
              $(tabHeader).append(btnCloseTab);
              $(tabHeader).append('&lt;/li&gt;');
              $("#ulTab").append(tabHeader);
              var tabContent = $('&lt;div id="tabs-' + tabIndex + '"&gt;' + content + '&lt;/div&gt;');
              $("#tabs").append(tabContent);
              $("#tabs").tabs("refresh");
  
          }
  </code></pre>