我正在尝试使用jQuery的each()一次性对多个元素进行简单的DOM操作。我得到了一些我不理解的结果。
这里是一个jsFiddle,展示了我想要发生的事情和实际发生的事情:
我为什么得到当前的结果,如何达到期望的结果?
这里是一个jsFiddle,展示了我想要发生的事情和实际发生的事情:
http://jsfiddle.net/kthornbloom/4T52A/2/
这里是JS代码:
// Step One: Append one blue box within each grey box
$('.grey').append('<div class="blue"></div>');
// Step Two: Make one copy of the red box already there, and place it within the new blue box.
$('.grey').each(function () {
$('.red', this).clone().appendTo('.blue', this);
});
我为什么得到当前的结果,如何达到期望的结果?