Bookmarklet that adds a JavaScript Function
I am currently trying to make a Bookmarklet that adds, among other things, a DIV-Element to Page, I do this by adding the HTML-Code to the body.innerHTML and that works fine. On this DIV-Element there is a button that should allow to hide the added DIV. I therefore tried to add via JavaScript a JavaScript Function to the innerHTML called "function hideDiv()".
The new JavaScript is added to the body and it looks fine. But it doesn't work.

Short example:

    javascript:var b = document.body.InnerHTML; b=b+'<input type="button" onclick="javascript:alert("hello")"/>'; document.body.innerHTML = b;


This bookmarklet should add a button that shows an alert if its clicked. It adds the button but nothing happens when clicking on it. 

Is this a general issue? Can JavaScript add (working) JavaScript to a page?

Thanks and friendly regards.
Bookmarklet that adds a JavaScript Function
===

I am currently trying to make a Bookmarklet that adds, among other things, a DIV-Element to Page, I do this by adding the HTML-Code to the body.innerHTML and that works fine. On this DIV-Element there is a button that should allow to hide the added DIV. I therefore tried to add via JavaScript a JavaScript Function to the innerHTML called "function hideDiv()".
The new JavaScript is added to the body and it looks fine. But it doesn't work.

Short example:

    javascript:var b = document.body.InnerHTML; b=b+'<input type="button" onclick="javascript:alert("hello")"/>'; document.body.innerHTML = b;


This bookmarklet should add a button that shows an alert if its clicked. It adds the button but nothing happens when clicking on it. 

Is this a general issue? Can JavaScript add (working) JavaScript to a page?

Thanks and friendly regards.