开发者

jQuery find width of each li element?

anyone know a way to find the width of each li within the ul?

I tried

var totalWidth;
jQuery("ul li").each(function() { totalWidth += jQuery(this).outerWidth(); });

But didn't work..开发者_如何学JAVA.


You need to initialize the variable first:

var totalWidth = 0;

...otherwise you're starting out effectively doing:

undefined += jQuery(this).outerWidth();

...which results in NaN for subsequent iterations:

NaN += jQuery(this).outerWidth();


Initiate the variable as 0. Your code seems like it should work

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜