In my attempt to learn core JavaScript, I am now learning about EventListeners.
My problem is that in code below EventListener not being fired in IE (working just fine in Firefox and Chrome).
Can somebody please tell me what I am doing wrong?
My code is:
<p>The first captain of the USS Enterprise NCC-1701 was
<a id="wikipedia" href="http://en.wikipedia.org">Christopher Pike</a>.
</p>
<script type="application/javascript">
var link = document.getElementById("wikipedia");
// for firefox and other browsers
if (typeof link.addEventListener != "undefined")
{
link.addEventListener("click", clickListener, false);
}
// IE only
else if (typeof link.attachEvent != "undefined")
{
link.attachEvent("onclick", clickListener);
}
function clickListener()
{
var link = document.getElementById("wikipedia");
link.setAttribute("href", "www.mysite.com/");
open("http://www.mysite.com");
return false;
}
</script>