1- You should try to avoid adding scripts in the head as it makes slow rendering page. If you really need to do so may be you could look for defer / async scripts.
2- You should try to put the script at bottom in order to make browser rendering all the html and css as fast as possible.
3- Finally at the bottom you should call in the load page. For example in jquery.ready like this doc says, search for jquery ready event. In that moment you should add a listener to the button you need by calling a jquery selector on the button, search for jquery selector, finally you add the click event, search for jquery click event, and then you process what you need inside that callback.
Here is a fiddle.
[https://jsfiddle.net/d6zfqpc6/][1]
Jquery acts as a good polyfill also to somethings :).