Traverse of a tree in javascript
<p>I have a variable in javascript  like below:</p>

<pre><code>var treeNode = [{
    "id": "T1"
  }, {
    "id": "T2",
    "children": [{
        "id": "T3"
      }, {
        "id": "T4"
      }, {
        "id": "T5",
        "children": [{
            "id": "T6"
          }, {
            "id": "T7"
          }, {
            "id": "T8"
          }
        ]
      }, {
        "id": "T9"
      }, {
        "id": "T10"
      }
    ]
  }, {
    "id": "T11"
  }, {
    "id": "T12"
  }
];
</code></pre>

<p>Node t3,t4,t5,t6,t7,t8,t9,t10 are the child of node t2.</p>

<p>each node has a link of deactivate .when click on deactivate two link active and delete create.mentioned in image:</p>

<p><img src="http://i.stack.imgur.com/5hlhy.png" alt="enter image description here"></p>

<p>i want to create same active and delete link on all child node of parent node.for example
if i click on deactivate link of T5 then active and delete link will show on T6,T7,T8 also
and
if i click on deactivate link of T2 then active and delete link will show on T3,T4,T5, T6,T7,T8,T9,T10 also</p>

<p>I tried below recursive code.but i think this is not a right approach.please advice.</p>

<pre><code>var objTreeNode = eval(treeNode);
trav(objTreeNode);

function trav(TreeNodeObj){
    var i=0;
    for (i=0;i&lt;TreeNodeObj.length;i++){
        if(!TreeNodeObj[i].children){
            if(objID==TreeNodeObj[i].id(){ //if click on T2 then get T2 as objID
                document.getElementById('span_'+objID).innerHTML = '&lt;a href="javascript:activate(\'' + objID + '\');"&gt;Activate&lt;/a&gt;    &lt;a href="javascript:deleteNode(\'' + objID
                Delete&lt;/a&gt;';
            }
        }
        else{

            childObj = TreeNodeObj[i].children;

            trav(objTreeNode)
        }
    }

}
</code></pre>
