I'm trying to insert JavaScript into an HTML page with JavaScript, after the page has already loaded, but I can not 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 can not put the code inside onclick
!