I think yours check function not returns function which is needed to assign as callback for onclick event, then
but.onclick = check;
for example in case:
var check = function() {
return function(){
/* some logic eg. dependent of arguments 'parent' function' */
} }
//works
but.onclick = check('somethingImportant');
All right, but there is a problem if you wanted to assign several callbacks for these event :)
It would be better if you know about addEventListener / attachEvent
but.addEventListener( 'click', check,true );
but.addEventListener( 'click', check2,true );
Afterwards if needed use removeEventLister or detachEvent to detach function(s);
However - try to play with jquery :)
var check = function(){/* do something */};
$('#addButton').append(
$('<input type="button" value="New Button"/>')
).click( check );
or
$('#addButton').append(
$('<input/>' ).attr( 'type', 'button' ).val( 'New Button' ) )
.click( function(){ /* do something */ } )
);
then
$('#addButton').unbind( 'click' ) // unbind( 'click',check )
And much more posibilities to doing that :)
check()? If you want check to be invoked upon a button click, remove the parenthesis:but.onClick = check;