I would change the line where you assign the handler to remove the parentheses so that you assign a function, not the results of a function:
You might also try assigning the handler after you have added the button to the document.
You might also want to rewrite the code to use a cross-browser library. jQuery has cross-browser support for creating elements and assigning handlers.