开发者

Is there an equivalent to jQuery's .unwrap() for Dojo?

开发者 https://www.devze.com 2023-02-20 16:21 出处:网络
I have a scenario similar to this: <div class=\"DivParent\"> <div class=\"Child1\"></div>

I have a scenario similar to this:

<div class="DivParent">
   <div class="Child1"></div>
   <div class="Child2"></div>
   <div class="Child3"></div>
</div>

I want an HTMLObject of Child1, Child2, and Child3 w/o the DivParent parent.

If I was using jQuery I could say:

var HTMLObjectIWant = $('.Parent > div').unwrap();

But I'm not ... I'm using Dojo and I would love to see this done in Dojo. Also- the order (Child1, Ch开发者_开发知识库ild2, Child3 is very important).

Thanks in advance.

-Mike


dojo.unwrap = dojo.unwrap || function(/* node ID or node */ n) {
    var node = dojo.byId(n).parentNode;
    dojo.query(' > *', node).forEach(function(childNode) {
        dojo.place(childNode, node, 'before');
    });

    dojo.destroy(node);
}

You'll probably want to neaten this up, for example currently it throw an error if n is undefined.

0

精彩评论

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