操作元素的相关方法

    xiaoxiao2022-07-12  136

    元素1.appendChild(元素2):向元素1中追加元素2元素1.insertBefore(元素2,元素1.firstElementChild):把新的子元素插入到第一个子元素的前面元素1.replaceChild(元素2,元素3);:元素1中元素3用元素2来替换元素1.removeChild(元素1.firstElementChild):移除元素1中的第一个子元素移除所有子元素 //点击按钮,移除dv元素下的所有子元素 btn.onclick=function () { while(dv.firstElementChild){ dv.removeChild(dv.firstElementChild); } };
    最新回复(0)