4

Lets say the JavaScript scheduler has one item in its queue which will delete a div element. Earlier, we'd setup listeners for click events on this div element. The scheduler will schedule this deletion task as soon as its done with its current work (which could be anything). At this moment we click the soon-to-be-deleted-div and callbacks to this click's listeners are added to the queue.

I assume the schedule queue is fifo (am I right?), so the div will first be deleted and after the deletion the callbacks for the divs click listeners will be raised.

Have I captured the sequence of events correctly, or would deleting this element cause the click listener callbacks to be pulled from the queue?

ccunni
  • 135
  • 1
  • 2
  • 7
  • 2
    You should look at this answer: http://stackoverflow.com/questions/2732818/if-you-delete-a-dom-element-do-any-events-that-started-with-that-element-contin#answer-2732982 – Royce Feng Sep 26 '12 at 01:26
  • It should be noted that `removeChild` doesn't actually _delete_ anything, the element only becomes GC'd when there are no more references to it, so it should still exist (though outside of the DOM tree) until the event is finished, because _the event holds a reference to it_. I would assume similar behaviour when modifying `innerHTML` but haven't tested it. – Paul S. Sep 26 '12 at 02:11

2 Answers2

0

The click event would enter the queue at the end of the queue. So the element should not be in the DOM to be clicked. There should be no event captured.

robert
  • 5,093
  • 2
  • 20
  • 21
0

Thanks to Royce Feng for the pointer to

If you delete a DOM element, do any events that started with that element continue to bubble?

The answer is: It depends on the browser. Check that link for details

Community
  • 1
  • 1
ccunni
  • 135
  • 1
  • 2
  • 7