0
I’m trying to insert Javascript into an HTML page with Javascript, after the page has already loaded, but I can’t make the new code work , what’s the problem?
var javascript = "<script> function alerta() { alert('ok'); }</script>";
var button = "<button type='button' onclick='alerta();'>start</button>";
var body = document.getElementsByTagName('body')[0];
body.insertAdjacentHTML('beforeend', javascript);
body.insertAdjacentHTML('beforeend', button);
Note: I cannot put the code inside the onclick
!
What would that tag be
<javascript>
?– MagicHat