im writing on a library i want to include on different pages who might already use the onchange event - is there any way to attach my event to onchange without removing the original one?
EDIT:
onchange on the window obj. not only a single element - onchange as in a hash change in the url etc. sorry if i confused them!
Using jQuery's
.change()
function to assign anonchange
handler will not override existingonchange
events (or other jQuery-assigned handlers). See a working demonstration here: http://jsfiddle.net/nrabinowitz/EyKdm/If I'm correct it sounds like you want to inject new code into an existing event. This may help you if you want a pure JavaScript solution and here is a fiddle demonstrating the feature. http://jsfiddle.net/VZCve/1/
EDITED: Now that the tags are changed and you are reference jQuery in your Question
jQuery will continue to bind new functions using jQuery.change().
note the following will execute all change functions assigned
When you trigger the change event for the element in the selector you will receive 3 alerts.
Note the order of the events firing is dependent on the order each function was bound to the element.
Here is a simple fiddle demonstrating the functionality in jQuery http://jsfiddle.net/VZCve/
Newer browsers have an
addEventListener
which can do it but dean.edwards solution is betteris more compatible with older browsers
you could also use a costem eventhandeler(s) whitch call array's of functions (done properly you could handle the
return
value of the sub-functions to decide if you want to run the next function, also couts forevent
code not tested please comment before downvote