Add event listener to anchor link
<html>
<head>
<title>Onclick</title>
<script type="text/javascript">
function handleclick() {
document.write("Clicked");
return false;
}
</script>
</head>
<body>
<p><a id="link1" href="#">Click Here</a></p>
<script type = "text/javascript" >
var link1 = document.getElementById("link1");
if (typeof window.addEventListener != "undefined") {
link1.addEventListener("click",handleclick,false);
} else {
link1.attachEvent("onclick",handleclick);
}
</script>
</body>
</html>
Related examples in the same category