Much like elsewhere in JavaScript Land, the principle for interaction is simple--attach an event listener to an element and do something when it's triggered. We add and remove listeners to and from selections with the .on() method, an event type (for instance, click), and a listener function that is executed when the event is triggered.
We can set a capture flag, which ensures that our listener is called first and all the other listeners wait for our listener to finish. Events bubbling up from children elements will not trigger our listener.
You can rely on the fact that there will only be a single listener for a particular event on an element because old listeners for the same event are removed when new ones are added. ...