Answers for "javascript replace element"

0

javascript replace element

// select the element that will be replaced
	var el = document.querySelector('div');
	
	// <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>';
	
	// replace el with newEL
	el.parentNode.replaceChild(newEl, el);
Posted by: Guest on March-28-2021
0

replace element javascript

// select the element that will be replacedvar el = document.querySelector('div');
// <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>';
// replace el with newELel.parentNode.replaceChild(newEl, el);
Posted by: Guest on March-23-2020
-1

javascript replace element

<html>
<head>
</head>
<body>
  <div>
    <a id="myAnchor" href="http://www.stackoverflow.com">StackOverflow</a>
  </div>
<script type="text/JavaScript">
  var myAnchor = document.getElementById("myAnchor");
  var mySpan = document.createElement("span");
  mySpan.innerHTML = "replaced anchor!";
  myAnchor.parentNode.replaceChild(mySpan, myAnchor);
</script>
</body>
</html>
Posted by: Guest on January-07-2021

Code answers related to "javascript replace element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language