This is my code:
var Tree = ( function ( _Obj ) {
var _E,
_N;
_Obj.forEach ( function ( e ) {
_E = document.createDocumentFragment();
if ( "tagName" in e ) {
_N = document.createElement( e.tagName );
}
if ( "childNode" in e ) {
_N.appendChild( Tree ( e.childNode ) );
}
});
_E.appendChild ( _N );
return _E;
});
And here the parameter of that function:
Fragment = [{ // firstNode
"tagName" : "div",
"childNode" : [{
"tagName" : "p",
"childNode" : [{
"tagName" : "string",
"childNode" : [{
"tagName" : "span",
}]
}]
}]
},
{ //secondNode
"tagName" : "div",
"childNode" : [{
"tagName" : "p",
"childNode" : [{
"tagName" : "span",
"childNode" : [{
"tagName" : "div"
}]
}]
}]
}
];
This code should return a document fragment with EVERY object of the var Fragment
. If you look, the JSON is based on a tagName
and childNode
elements; for each object depends on one tagName
, so the function return one new element with the same name.
But something goes wrong here, the function only returns the SECOND NODE of the Fragment
:
#document-fragment
|_<div>
|_<p>
|_<span>
<div></div>
</span>
</p>
</div>
That this is equal to:
{
"tagName" : "div",
"childNode" : [{
"tagName" : "p",
"childNode" : [{
"tagName" : "span",
"childNode" : [{
"tagName" : "div"
}]
}]
}]
}
But, what happend with the FIRST NODE?