<input type="button" onclick="alert('Yes');" value="Test" id="test"> <script> window.onload = function () { var el = document.getElementById('test'); alert(el.getAttribute('onclick')); } </script>