How to move an element into another element?

前端 未结 15 2533
無奈伤痛
無奈伤痛 2020-11-22 03:35

I would like to move one DIV element inside another. For example, I want to move this (including all children):

...
15条回答
  •  一整个雨季
    2020-11-22 04:10

    For the sake of completeness, there is another approach wrap() or wrapAll() mentioned in this article. So the OP's question could possibly be solved by this (that is, assuming the

    does not yet exist, the following approach will create such a wrapper from scratch - the OP was not clear about whether the wrapper already exists or not):

    $("#source").wrap('
    ') // or $(".source").wrapAll('
    ')

    It sounds promising. However, when I was trying to do $("[id^=row]").wrapAll("

    ") on multiple nested structure like this:

    It correctly wraps those

    ...
    and ... BUT SOMEHOW LEAVES OUT the . So I ended up use the explicit $("row1").append("#a_predefined_fieldset") instead. So, YMMV.

提交回复
热议问题