开发者

How to wrap 2 divs into another on on the fly?

开发者 https://www.devze.com 2023-02-22 15:24 出处:网络
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 +

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');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号