jQuery: appendTo parent

前端 未结 4 2343
灰色年华
灰色年华 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:40

    I made a little example and I hope you mean the same thing...

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

提交回复
热议问题