function insert ele(){ var oTest = document . getelementbyid(“box-one“);var new node = document . createelement(“div“);var reforeNode = document . getelementbyid(“p 1“);newNode.innerHTML =“這是壹個新圖標“;otest . insert before(new node,reforenode . next sibling);//新創建的元素節點插入到id為P1的節點元素之後。}
第二個//自定義函數向後插入函數插入器(newelement,targeted element){ var parent = targeted element。parentnode如果(父母。last child = = target element){//如果最後壹個節點是目標元素,則直接添加。因為默認是最後壹個parent . a(new element);} else {//如果不是,則將其插入目標元素的下壹個同級節點之前。即目標元素後面的parent . insert before(new element,target element . next sibling);}}