jQuery: appendTo parent

前端 未结 4 2346
灰色年华
灰色年华 2021-02-19 02:59

I can\'t seem to get the appendTo to work. What do I do wrong?

$(\'div:nth-child(2n) img\').appendTo(parent);

Current markup:

&         


        
4条回答
  •  醉话见心
    2021-02-19 03:26

    Is this what you're after?

    $('.container > img').each(function () {
        $(this).parent().append(this);
    });
    

    It simply takes the within every container and moves as the first child of the container.

提交回复
热议问题