This article mainly introduces the use of JavaScript replacement elements ReplaceChild (), need friends can refer to the following
ReplaceChild (A,B) is a parameter that replaces an existing element in a document A: the node to be inserted, parameter B: the node code to be replaced is as follows: var odiv = document.getElementById ("Guodiv"); var Ospan = document.createelement ("span"); ospan.innerhtml = "4"; var firschild = Odiv.firstelementchild? oDiv.firstElementChild:oDiv.firstChild var returnnode = Odiv.replacechild (Ospan, firschild); Replaces the first element, returning the replaced element alert (returnnode.innerhtml); 1 var lastchild = Odiv.lastelementchild? ODiv.lastElementChild:oDiv.lastChild; Ospan = document.createelement ("span"); ospan.innerhtml = "5"; Returnnode = Odiv.replacechild (Ospan, LastChild); Replace the last one, return the replaced element alert (returnnode.innerhtml);//3 code is as follows: <div id= "Guodiv" > <span>1</span> <span >2</span> <span>3</span> </div>