Zdeno
16 Jul 2012, 4:26 AM
When you check source code of function insertChild, you will find following code:
insertChild: function(index, node) {
var sibling = this.childNodes[index];
if (sibling) {
return this.insertBefore(node, sibling);
}
else {
return this.appendChild(node);
}
},
Why did you use appendChild function when sibling does not exists? Instead of appendChild you have to check count of childNodes and then you can say if you want put node to childNodes or you have to call appendChild. AppendChild will add node at the end of array but i wanted insert node to specific index. Thats why i used insertChild instead of appendChild.
insertChild: function(index, node) {
var sibling = this.childNodes[index];
if (sibling) {
return this.insertBefore(node, sibling);
}
else {
return this.appendChild(node);
}
},
Why did you use appendChild function when sibling does not exists? Instead of appendChild you have to check count of childNodes and then you can say if you want put node to childNodes or you have to call appendChild. AppendChild will add node at the end of array but i wanted insert node to specific index. Thats why i used insertChild instead of appendChild.