Since the "evt" event object is not passed from the parameter, is it possible to get this object?
No, not reliable. IE and some other browsers make it available as window.event (not $(window.event) ), but many browsers do not.
You better pass an event object to a function:
<a href="#" onclick="myFunc(event, 1,2,3)">click</a>
This works even in browsers other than IE because they execute code in a context that has an event variable (and works in IE because event allows window.event ). I tried this on IE6 +, Firefox, Chrome, Safari and Opera. Example: http://jsbin.com/iwifu4
But your best bet, of course, must correctly connect the event:
HTML:
<a href="#">click</a>
JavaScript using jQuery (since you are using jQuery):
$("selector_for_the_anchor").click(function(event) {
... or if you really want to pass event to myFunc :
$("selector_for_the_anchor").click(function(event) { myFunc(event, 1, 2, 3); });
The selector can be anything that identifies the anchor. You have a very rich selection to choose from (almost all CSS3, as well as some). You can add an id or class binding, but again, you have other options. If you can use what is in the document and not add something artificial, great.
TJ Crowder May 01 '11 at 15:49 2011-05-01 15:49
source share