use on handlers instead of click
put the JS in an immediately invoked function expression to keep variables and functions out of global scope