Reputation: 1527
I have a link: <a href="/somelink" id="link_test" onclick="return func(event);">Link</a>
.
I want to remove this onclick
attribute and add a click
event listener by addEventListener
.
I tried:
ge("link_test").addEventListener('click',function(){
return func(window.event);
},false);
also:
ge("link_test").addEventListener('click',"return func(window.event);",false);
No result. Is it possible to do it by addEventListener
(and how)?
PS: actually I have a cross-browser variant of addEventListener
func, but not important in this case.
Upvotes: 1
Views: 206
Reputation: 100175
Try:
var anch = document.getElementById("link_test");
anch.addEventListener ("click", function (event) {
event.preventDefault();
func(event)
}, false);
Do you mean something like this
Upvotes: 1