JavaScript addEvent function
- by Yalmaz Khalil
I have an addEvent function:
function addEvent(elem, event, func ) {
if (typeof (window.event) != 'undefined')
elem.attachEvent('on' + event, func);
else
elem.addEventListener(event, func, false);
}
<a href="#" id="link">link</a>
and I'm trying to add the following to window.onload:
addEvent(window, 'load', function (){
// add another event
var link= document.getElementById('link');
addEvent(link, 'click', function () {alert('Hi'); });
});
My question is: why does the link event not work?