View Full Version : Multiple events one function
Rain Lover
05-14-2014, 03:19 AM
The following works with no problem:
element.oninput = go;
element.onchange = go;
...
But isn't there a shorter way to achieve the same result? Do we have to repeat the same line for each event?
jscheuer1
05-14-2014, 07:13 AM
In ordinary javascript:
element.oninput = element.onchange = go;
If using recent versions of jQuery (with the newer 'on' function):
$(element).on('input change', go);
Rain Lover
05-14-2014, 07:23 AM
element.oninput = element.onchange = go;
Thanks for the answer! I never thought it could be so simple.
onchange is added to support IE and oninput for other browsers to handle <input type="range">. Does the events order make any difference?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.