Reputation: 1319
I have been using jQuery to create a simple child list, however the style of child list I am generating is as thus:
parent
-> child1
-> child2
-> childN
The style of list I want to generate needs to render like this.
parent
-> child1
--> child2
--->childN
So that a child is appended a new child node.
Currently I have been utilising jQuery's .last().append() features however they only seem to be able to generate example 1 and for some reason i can not for the life of me work out this very basic problem, should I utilise prepend(), but i feel as though that may not work correctly ?
var nodeSets = document.createElement(arrayElems[0]);
for (var i=1; i < arrayElems.length; i++) {
$(nodeSets).last().append(document.createElement(arrayElems[i]));
}
Upvotes: 0
Views: 98
Reputation: 8059
HTML
<div id='target'/>
javascript:
var elems=[
'<div>test</div>',
'<div>test2</div>',
'<div>test3</div>',
'<div>test4</div>',
'<div>test5</div>',
'<div>test6</div>',
'<div>test7</div>'
];
var lastelem=$('#target');
for (var n in elems) {
var e=$(elems[n]);
lastelem.append(e);
lastelem=e;
}
Upvotes: 3