I am trying to set the onclick event using javascript. The following code works:
var link = document.createElement(\'a\');
link.setAttribute(\'href\', \"#\");
l
Setting an attribute doesn't look right. The simplest way is just this:
link.onclick = function() {
alert('click');
};
But using addEventListener as JCOC611 suggested is more flexible, as it allows you to bind multiple event handlers to the same element. Keep in mind you might need a fallback to attachEvent for compatibility with older Internet Explorer versions.