Add a "piggyback" event to an existing onClick of an image

I have an image that already has an onClick event (a simple window.print(); command). I am trying to figure out how I can add another function to this onClick so when a user clicks this button not only will the print window appear but another js function will also fire off. How do I accomplish this? Unfortunately I am not able to simply manually add the function to the onClick so is there a way to listen for all “window.print();” events and send a second event (my js function) at that time?

Thanks!!

No, but you can listen for all click events on that element. Get rid of the inline onclick (it’s not onClick by the way) event handler and use this:

document.getElementById('the_image').onclick = function() {
  window.print();
  doOtherStuff();
}