Why the difference?
document.getElementById('click').onclick = a.replaceChild(c,b) --- replaces the element without me clicking the button
but onclick="a.replaceChild(c,b)" --- replaces the element only after the button is clicked
<div id="container">
<p id="welcome">no greetings yet</p>
<p id="products">oreo ice-cream</p>
</div>
<button id="click" **onclick="a.replaceChild(c,b)"**>CHANGE</button>
<script>
var a = document.getElementById('container');
var b = document.getElementById('welcome');
var c = document.createElement('h2');
c.id = 'new';
c.innerHTML = "WELCOME";
**document.getElementById('click').onclick = a.replaceChild(c,b);**
</script>
..
` replaced by `...
` – Alive to die - Anant Dec 08 '17 at 04:27