Do you prefer the dispatchEvent way with at least 3 different ways to initialize an event usually fired only to call the callback?
It is this:
a.addEventListener("click", function(evt){
location.href = evt.target.href;
evt.preventDefault();
return false;
}, false);
// powerful uh? now think
// when you used something different
// from defaults ...
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent(
"click",
true,
true,
this,
0,
0,
0,
0,
0,
false,
false,
false,
false,
0,
null
);
a.dispatchEvent(evt);
against what I think is often all we need:
a.attachEvent("onclick", function(){
location.href = event.srcElement.href;
return event.returnValue = false;
});
a.fireEvent("onclick");
and that's it :)
1 comment:
The beast are becoming strong, don't you think? ;)
Post a Comment