Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting a native browser event object to a jQuery event object
    primarykey
    data
    text
    <p>I am assigning an event handler function to an element through the native browser onclick property:</p> <pre><code>document.getElementById('elmtid').onclick = function(event) { anotherFunction(event) }; </code></pre> <p>When I'm in <code>anotherFunction(event)</code>, I want to be able to use the event object like I would with the event object you get in jQuery through the <code>.on()</code> method. I want to do this because the jQuery event object has properties and methods such as <code>.pageX</code>, <code>.pageY</code> and <code>.stopPropagation()</code> that work across all browsers.</p> <p>So my question is, after I've passed in the native browser event object into <code>anotherFunction()</code>, how can I turn it into a jQuery event? I tried <code>$(event)</code>, but it didn't work.</p> <p>The obvious question here is: why don't you just use jQuery <code>.on</code>, <code>.bind</code>, <code>.click</code> 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 <code>.on</code> et al in IE6 and IE7 creates DOM leaks and eats up memory very quickly (test for yourself with Drip: <a href="http://outofhanwell.com/ieleak/index.php?title=Main_Page" rel="noreferrer">http://outofhanwell.com/ieleak/index.php?title=Main_Page</a>). Setting onclick behavior via <code>.onclick</code> is the only option I have to render quickly in IE6 and IE7.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload