开发者

is it possible to get the total width of a jquery tab?

is it possible to get the width of the different tabs with different lengths of text inside?

for instance

| tab 1 | motion sickness | computer |

the tab 1 = 20px

motion sickness tab = 100px

computer tab = 60p开发者_JS百科x

something like that


It depends on exactly how much of the width you want. You can use outerWidth to include margins or width to get the basic width.

Where tab1 and motionSickness are element id's:

var width = $('#tab1').width();
var outerWidth = $('#motionSickness').outerWidth();
var totalWidth = $('#tab1').width() + $('#motionSickness').width();

ADDITION:

If you want to loop through them, you can to it with the same id's as above like so:

var totalWidth = 0;
$('#tab1, #motionSickness').each(function(){
   totalWidth += $(this).width();
});

You can also give all those tab elements a class and then change $('#tab1, #motionSickness') to $('.tab'). Also, may help to brush up on the jQuery API for the correct selectors and methods and such.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜