Javascript

Modern Javascript Programming

Multiple event handlers for an element in JavaScript

This afternoon I caught a question posted in phpvietnam group:

"I have an input element with the property onclick="doSomeFunction();". Now I want to add another function, ie onclick="doSomeFunction(); doSomeFunction2();", can I do this with JavaScript? Thanks in advance!" (translated)

Source (in Vietnamese): http://groups.google.com/group/phpvietnam/browse_thread/thread/c7a8688875a320c3

After answering his question, I just want to share my experience when working with JavaScript event handler. I will show you 4 event registration models for the time beings of its use; the way to use context and this keyword in function handler. My approach is that the event object will be passed as 1st parameter to the function handler and this has to refer to the element triggering that event.

Syndicate content