Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
 
PREVIOUS NEXT
Tagged: #javascript #replace #element
ADD COMMENT
Topic
Name
4+3 =