function x() { let btn = document.getElementById("btn"); btn.on = function() { console.log("XXXXXXSS"); } btn.on(); } </script> </head> <body> <button id="btn" onclick="x()">Press </button> </body>