I have 2 divs that I am creating from an array:
$.each(data, function(i,item) {
$('<img/>').attr("src开发者_StackOverflow", 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');
});
And I want to wrap them all in a div, like this:
<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>
I am using: $('<div class="sex"></div>').appendTo('.mutual_row');
or:
$('.mutual_friends, friends-name1').wrap('<div class="sex"></div>')
But they give the wring result wrappin gthem all in one div called sex
$.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');
});
精彩评论