JQuery将UL附加到另一个DIV

时间:2013-10-08 16:42:43

标签: javascript jquery html css

我有这个DIV:

    <div id="video_container" class="barra">
        <ul>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/Gy3lrgVakII" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/AnwKqlhzCM4" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/wLJM0oi7o9A" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/NRWrYGaqIO8" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/ICUhpeXDrwQ" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/DDVWXbVxIkI" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/ntD69DBs8Q8" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/fuTmK5WHQ18" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/IpUwiyID_Kk" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/snISa71nM_k" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/z6VuNTPuChc" frameborder="0" allowfullscreen></iframe></li>
            <li><iframe width="450" height="253" src="//www.youtube.com/embed/NKzwcbidanM" frameborder="0" allowfullscreen></iframe></li>
        </ul>
    </div>
<div id="video_container_mobile"></div>

我想填充另一个内容相同的div (<ul>...</ul> )

我有这个:

var list = $("#video_container_mobile").append('<ul></ul>').find('ul');
        $("#video_container ul li").each(function() {
            var el = $(this);
            list.append(el);
        });

这是有效的,但这是从原来的div中删除的,我追加的列表。

见下图:

THE IMAGE FROM FIREBUG

并查看FIddle:

http://jsfiddle.net/YgQJM/

我想在2 DIV中保留相同的内容......任何人都可以帮忙吗?

2 个答案:

答案 0 :(得分:4)

$('#video_container_mobile').append($('#video_container ul ').clone())

http://jsfiddle.net/edY45/

答案 1 :(得分:1)

可能不像@Hussein那样干净,但

$('#video_container_mobile').append($('#video_container').html());