将css从类收集到数组中,使用jQuery提供给另一个类

def*_*ime 0 css jquery

我有两组元素,都有相同数量的元素.我想知道如何从第一组中收集宽度(宽度是可变的),然后按照收集的顺序将其提供给第二组.

<div class="a">This element might have a width of 100px</div>
<div class="a">..while this one might be 50px</div>
<div class="a">..and this one is maybe 75px</div>
Run Code Online (Sandbox Code Playgroud)

收集到数组[100,50,75],然后将其传递给另一组元素.

<div class="b">give me the 100px width</div>
<div class="b">and me the 50px width</div>
<div class="b">and me the 75px width</div>
Run Code Online (Sandbox Code Playgroud)

Cla*_*edi 5

像这样的东西可以做到这一点

$('.a').each(function(index) {
    var thisWidth = $(this).width();
    $('.b').eq(index).width(thisWidth);
})
Run Code Online (Sandbox Code Playgroud)

DEMO