What Is Meant By "onload=foo(event)"?
I am new to JS and found this code section:
<body>
<span id="sp1">
<img src="aurora.gif" onload="ev1(event)">
</span>
</body>
As far I understood, the onload
attribute gets triggered if the entire HTML Doc finished "loading".
But I don't really understand, whats passed to the ev1
function if the onload
attribute is triggered. What is event
in this case?
Here is the source code
Answer
It's hooking up a handler to the image's load
event and passing the event object for the event into the handler. The event
object exists reliably cross-browser within the context of the onload
attribute-style event handler: On IE, it's a global; on Firefox, it's a local within a synthetic function created for the onload
handler; on Chrome, I think it's both. :-)
Note that the ev1
function must be a global, which is one of many reasons not to use onxyz
-attribute-style event handlers.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM