Try this code,
Script
function $(id) {
return document.getElementById(id);
}
$('tester').addEventListener('click', function () {
alert('Hello world');
});
When you console this $('tester')
selector, it simply returns <a id='tester'>CLICK ME</a>
which is a html element not an object so you cannot use onclick directly. Instead you have to use addEventListener
or attachEvent
to bind a click event
Demo JS http://jsfiddle.net/K3eAc/4/