I want to compare the change of a DOM node after a user event is fired on it; but I don’t know on which element a user would fire, so my idea is to (1) save the DOM tree before an event and (2) compare the saved tree with the updated DOM tree when an event is fired.
My question are
(1) is there any better way? and
(2) if there is no other way, what would be the fast algorithm to compare two DOM trees?
Since events bubble up, you could simply attach an event listener to the
windowobject which catches all events, regardless of where they originated. You can examine the passedeventobject forevent.targetto see where it originated.