如何获取数组中每个dom元素的宽度?

her*_*iim 2 javascript arrays jquery for-loop

footLinks是通过jquery选择的DOM元素的数组.这是我正在处理的代码:

var footLinks = $('.links li');

for (var i = 0; i < footLinks.length; i++) {
    var footLink = footLinks[i];
    var footLinkWidth = footLink.width();
    console.log('Width: ' + footLinkWidth);
}
Run Code Online (Sandbox Code Playgroud)

如何获得每个元素的宽度?

Nik*_*kos 6

我认为如果你这样写它会更好:

$('.links li').each(function(d) {
    console.log("Width: "+$(this).width())
});
Run Code Online (Sandbox Code Playgroud)