//Assuming there is an element with ID='test' on the page document.getElementById('test').onclick = function(e) { alert('Element clicked!'); };