showing results for - "javascript replace element"
Emily
20 May 2020
1	// select the element that will be replaced
2	var el = document.querySelector('div');
3	
4	// <a href="/javascript/manipulation/creating-a-dom-element-51/">create a new element</a> that will take the place of "el"
5	var newEl = document.createElement('p');
6	newEl.innerHTML = '<b>Hello World!</b>';
7	
8	// replace el with newEL
9	el.parentNode.replaceChild(newEl, el);
Valentina
06 Feb 2017
1// select the element that will be replacedvar el = document.querySelector('div');
2// <a href="/javascript/manipulation/creating-a-dom-element-51/">create a new element</a> that will take the place of "el"var newEl = document.createElement('p');newEl.innerHTML = '<b>Hello World!</b>';
3// replace el with newELel.parentNode.replaceChild(newEl, el);
Eden
23 Jun 2018
1<html>
2<head>
3</head>
4<body>
5  <div>
6    <a id="myAnchor" href="http://www.stackoverflow.com">StackOverflow</a>
7  </div>
8<script type="text/JavaScript">
9  var myAnchor = document.getElementById("myAnchor");
10  var mySpan = document.createElement("span");
11  mySpan.innerHTML = "replaced anchor!";
12  myAnchor.parentNode.replaceChild(mySpan, myAnchor);
13</script>
14</body>
15</html>
16
queries leading to this page
replace elementdom substitute elementreplace an element in dom javascripthtml element replacejavascript replace node elementsubstitute element jsreplace element in dom javascriptreplace element in domelement replace in jsreplace dom element javascriptreplace an element in jsjs replace elemetnreplacer element jsdom replace elementjs replace documenthow to use the dom to replace any element with a new elementhow to replace element in javascripthow to replace element javascriptw3schools replace javascriptjavascript element replace withreplace element javascript htmlreplace html element javascripthow to find and replace html element in javascriptdocument replace elementreplace element content jsreplace document jsjavascript replace in dom elementjs replace element with anotherreplace created element javascriptjs replace elementreplace elements in javascriptreplace javascript html elementjavascript replace element textreplace elements javascriptreplace element javascritpjavascript replaceelemreplace element jsjs element replacejavascript refresh elementcreate elements and overwritehtml dom to replacejavascript replace html elementjavascript replace dom elementjs replace element w3js replace html elementjavascript replace element htmlnodejs replace html elementreplace document element javascriptreplace element with elementjs replace element with textreplace element text javascriptreplacechild javascriptreplace a part of an element javascripthow to replace html element in javascripthtml element replace javascriptjavascript document replace elementjavascript replace element in htmlhow to replace dom element in javascripthtml replace elementjavascript dom create element replace elementhow to replace element in jsjs replace text in elementjs replace an element in domjavascript dom replace elementreplace text element javascriptjs replace dom elementreplace elements jsreplace dom element content with another element javascriptjs replace text from elementhtml specific element replace javascriptjs replace dom element with anotherhtml element javascript replacehow to replace an element in jsreplace dom elementjavascript replace an html elementhtml dom replace element in javascripthow to replace an html element in jshow to replace an element in javascriptelement replace javascriptjs replace element htmljs replace element with another tagjavascript replace elementreplace in a element jselement replace jsreplace element domreplace div element javascriptjavascript element replace htmlreplace element by javascriptjavascript replace element with javascript replace indexhjs replace elementhow to replace an element in javascriptreplace html element with javascriptjavascript to to replace html elementsjs find element and replace textreplace element in javascriptreplace dom element in jsreplace the element in domreplace element javascripthow to replace an html element with javascriptjs document html replacereplace element html javascriptjs replace string with elementelement replace jsjs replace element in domreplace an elementhow to replace elements domjsdom replace elemetnjavascript replace a dom elementreplace html element jsjavascript replace element with elementreplace an element javascripthow to use the js dom to replace a html elementreplace an element in javascriptjs substitute elementjavascript replace element with htmljavascript replace with new elemtn domreplace html in javascriptjs dom replace elementjavascript element replacereplace element with javascriptjavascript replace element