Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Adding a node with its children
posted

Hello,

Is there a way to add a node to another node while preserving all the children of the node being added?

In javascript.

Parents
  • 5118
    Verified Answer
    posted

    Hi,

     I think you are looking for something like this:

     

    function AddChildNodesRecursive(childNode, parentNode) {

    var newChild = parentNode.addChild(childNode.getText());

    if (childNode.hasChildren()) {

    var children = childNode.getChildNodes();

    for (c in children) {

    var childSubNode = children[ c ];

    AddChildNodesRecursive(childSubNode, newChild);

    }

    }

    }

Reply Children