I am assigning an event handler function to an element through the native browser onclick property:
document.getElementById('elmtid').onclick = function(event) { anotherFunction(event) };
When I'm in anotherFunction(event)
, I want to be able to use the event object like I would with the event object you get in jQuery through the .on()
method. I want to do this because the jQuery event object has properties and methods such as .pageX
, .pageY
and .stopPropagation()
that work across all browsers.
So my question is, after I've passed in the native browser event object into anotherFunction()
, how can I turn it into a jQuery event? I tried $(event)
, but it didn't work.
The obvious question here is: why don't you just use jQuery .on
, .bind
, .click
etc to assign your event handling functions? The answer: I'm building a page that has a huge table with lots of clickable things on it. Unfortunately this project requires that the page MUST render quickly in IE6 and IE7. Using .on
et al in IE6 and IE7 creates DOM leaks and eats up memory very quickly (test for yourself with Drip: http://outofhanwell.com/ieleak/index.php?title=Main_Page). Setting onclick behavior via .onclick
is the only option I have to render quickly in IE6 and IE7.