Using events to decouple code

Through this book, we have used events, but they have always been triggered by jQuery or the browser but never by us. Now, that is about to change. Events are really great for the decoupling of code. Imagine a scenario where you and another developer are working together on an application. The other developer is going to supply your code with data. This data—let's call it the data source—will be available intermittently, unlike the previous example of supplying the data via a single Ajax call. Your code, the data reader, will render the data to the page when it becomes available. There are several ways that we could go about this.

The data source could provide a polling method for us to call. We would repeatedly call ...

Get jQuery Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.