13

I'm using a dynamic jQuery tab widget to add/remove tabs generated programmatically.

How do I check through jQuery and count how many existing tabs are present in the widget?

I'm using this code, but it doesn't work:

$('#container-1 > ul').tabs('add', tabName, name);

var newTab;

if ($('#container-1 > li').size() < 0) {
    newTab = $(tabName).css('display', 'block')
} else {
    newTab = $(tabName).css('display', 'none');
}

newTab.html('<iframe src="ViewPatient.aspx?pname=' + name 
       + '" width="100%" frameborder="0" scrolling="no" height="300"></iframe>');
Dan Herbert
  • 99,428
  • 48
  • 189
  • 219

2 Answers2

47

Just use the below code

$('#selector >ul >li').size();

where "#selector" is the selector you have used to create the tabs.

UPDATE

size() function doesn't exist any more, now the solution is:

$('#selector >ul >li').length;
Daria
  • 861
  • 11
  • 29
Wolfgang
  • 515
  • 1
  • 4
  • 2
20
var tabCount = $(tabContainer).tabs("length");
dmnc
  • 966
  • 1
  • 9
  • 19
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • 12
    This no longer works in jQuery-ui 1.10.0. http://jqueryui.com/upgrade-guide/1.9/#deprecated-length-method See Wolfgang's solution. – jcoffland Feb 09 '13 at 00:42