我从数组中创建了2个div:
$.each(data, function(i,item) {
$('<img/>').attr("src", item.media_path).wrap('<div class="friend_pic' + item.id + '"></div>').appendTo('.sex');
$('<div class="friends-name' + item.id + '" id="fname_' + item.id + '" />').html(item.fname).appendTo('.sex');
});
我想将它们全部包装在div中,如下所示:
<div class="sex">... the divs from the each function ...<div>
<div class="sex">... the divs from the each function ...<div>
<div class="sex">... the divs from the each function ...<div>
我正在使用:$('<div class="sex"></div>').appendTo('.mutual_row');
或:
$('.mutual_friends, friends-name1').wrap('<div class="sex"></div>')
但他们在一个名为sex
答案 0 :(得分:1)
$.each(data, function(i,item) {
var container = $('<div class="sex" />');
$('<img/>').attr("src", item.media_path).wrap('<div class="friend_pic' + item.id + '"></div>').appendTo(container);
$('<div class="friends-name' + item.id + '" id="fname_' + item.id + '" />').html(item.fname).appendTo(container);
container.appendTo('.mutual_row');
});