Javascript Event Listeners

Hi Guys,

var img1 = document.querySelector('.img-1');

img1.addEventListener('load', function() {
  // woo yey image loaded

img1.addEventListener('error', function() {
  // argh everything's broken

According to the example above is there any possibility to happened the event before we started listening for them.

I got this problem when I read this
Javascript Promises

Did you mean to say “have an event” instead of “happen event”?

Also, I do not understand what “before we start listen to that?” means. What do you mean by “that”?

Can you give us a little more detail of exactly what you are trying to do? Also, if you already have some HTML,CSS, or JavaScript, it would be great if you can share a link to the code or copy/paste it into a reply.

If you enter a code block into the forum, please put three backticks on a separate line before the code and three backticks on a separate line after the code to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


Thank u @RandellDawson for giving me your suggestion. I have updated my comment according to that.