count the number of existing tabs in jquery?

只愿长相守 提交于 2020-01-01 08:11:54

问题


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>');

回答1:


var tabCount = $(tabContainer).tabs("length");



回答2:


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;


来源:https://stackoverflow.com/questions/1175380/count-the-number-of-existing-tabs-in-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!