function hello() { alert('Hello world!'); } var isAttached = document.getElementById('btn').attachEvent('onclick', hello); if (isAttached == false) { alert('Attach failed!'); }