2013-04-06 80 views
1

我知道,要刪除DOM樹中某個位置的子節點,我可以這樣做;在節點x上追加孩子?

this.element.removeChild(this.element.childNodes[index]); 

我試圖找出是否有附加在節點x的孩子,就像上面,但相反的方式。在僞代碼中,它會像(我認爲)。

this.element.appendChild(child at node[index])); 

感謝您幫助我。

回答

1

也許你正在尋找insertBefore

this.element.insertBefore(element, this.element.childNodes[index]); 
+0

這將工作的偉大的感謝!正在尋找約15分鐘在mozilla開發和在這裏,但找不到任何東西,因爲我正在尋找錯誤的東西! – GriffLab 2013-04-06 23:27:52

+0

@CarlG請注意,不支持'insertAfter'方法。 – VisioN 2013-04-06 23:30:44

+0

我只是試圖尋找它,並想知道爲什麼沒有出現!雖然通過增加或減少1可以很容易地克服,再次感謝。 – GriffLab 2013-04-06 23:36:02