<input id="btnOK" type="button" value="test" /> <script type="text/javascript"> function aa(){ alert(this.id) } var obj = document.getElementById("btnOK"); if(obj.attachEvent){ obj.attachEvent('onclick', (function(){ return function(){ aa.call(obj) } })(obj)) } </script>