After recently writing an article on “ Writing A Better JavaScript Library For The DOM ”, I realized that the topic is indeed a very complex one and that it’s important to understand what exactly live extensions are and how they work. In today’s article, I will answer most questions that were asked regarding “ live extensions ” and help you get going with this new concept. The Responsibilities Of Live Extensions Event handling is one of the key principles of working with the DOM. Events are the primary means of receiving feedback from user interaction. Simple Event Binding In this first example, documentation and tutorials that cover DOM events is what I call “simple event binding”. You attach a listener for the desired event on the DOM element in which you expect it to happen on. link.addEventListener("click", function(e) { // do something when the link is clicked }, false); The first argument indicates the type of an event, the second argument is a listener, and the third argument defines an event phase (so-called “bubbling” or “capturing”).
↧