Both code samples contain the following construct
Code:
(function() {
...
})(jQuery);
which doesn't make any sense in that case. It creates an anonymous function with no parameter which will be immediately called with the parameter jQuery. The parameter will not be matched to anything so it will be lost.
The position of the code matters in that case because the function will be executed immediately and the element '#mybutton' will only exist before the end of the <body>
This is probably what you wanted to do instead
Code:
$(function() {
...
});