Tuesday, April 10, 2012

replace traditional event call with javascript event listener

With the following code:



<head>
<script type="text/javascript">
function popupMsg(msg) {
alert(msg);
}
</script>
</head>

<body>
<a href="http://www.xyz.com" onClick="popupMsg('This is pop up message')">xyz.com</a>
</body>


How can I replace onClick with addEventListener within anchor tag ?



Can it be done without assigning ID to the anchor tag?



Probably something like this:



<a href="http://www.xyz.com" something.addEventListener('click',popupMsg(SomeMsg),false)>xyz.com</a>




No comments:

Post a Comment