Skip to content

Instantly share code, notes, and snippets.

@googlicius
Last active November 23, 2017 07:43
Show Gist options
  • Save googlicius/3951ac84aeabc21d53de28999032a159 to your computer and use it in GitHub Desktop.
Save googlicius/3951ac84aeabc21d53de28999032a159 to your computer and use it in GitHub Desktop.
Method to add one or more function handler on an element's onload event...
/**
* Method to add one or more function handler on an element's onload event
* This is because onload cannot carry out many separate functions.
*
* @param {any} element DOM element
* @param {any} handler function
*/
const addOnloadHandler = (element, handler) => {
if (typeof element.onload === 'function') {
const pre_func = element.onload;
element.onload = () => {
pre_func();
handler();
}
}
else {
element.onload = handler;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment