In the following jQuery JavaScript code, what value does the parameter ‘e’ take on within the function? I’m having difficulty understanding this because this function cannot be passed an argument elsewhere in the code so how would having a parameter work? And how would I use parameters in such functions that are not named and not called anywhere else in the code?
$(document).ready( function() { $('div').each(function() { $(this).click(function(e){ //some code }); }); });
clicksets the event handler. The click handler gets called by the browser when the event occurs, and theeparameter contains information about that event.For keypress events, it contains which keys were pressed and what modifiers were pressed at that time (shift, control, etc.).
For mouse events, it contains the position of the click and which button was used.
See http://www.quirksmode.org/js/events_properties.html for more information about the properties of the event structure.