Home:ALL Converter>Event Handling with Function Literals

Event Handling with Function Literals

Ask Time:2013-08-25T21:47:57         Author:ajavad

Json Formatter

So I've been going through Head First JavaScript and I came to a section on Event Handling with Function Literals. The book explains that you can wire all your event handling in your 'script' tags. But I am confused on how I get multiple functions to fire off on one event. Here's my code:

//Event Handling with Function Literals
  window.onload = function(evt) {

//THIS IS BROKEN
    document.body.onresize = resizeImg();reportImgHeight();

//Onload: Functions to Execute -- THESE WORK    
    resizeImg();
    reportImgHeight();
  }

So specifically for this example, how do I get an "onresize" event to execute BOTH resizeImg and reportImgHeight (functions which I have defined elsewhere in my code). Thank you!

Author:ajavad,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18429636/event-handling-with-function-literals
Denys Séguret :

The cleanest solution is to use addEventListener :\n\nwindow.addEventListener('resize', resizeImg);\nwindow.addEventListener('resize', reportImgHeight);\n\n\nThis way you can decouple both bindings. \n\nNote also that you should bind the resize event to the window, not to a document part.",
2013-08-25T13:50:33
yy