Refactor js to not use the onclick handler