Events & Callbacks


An example of using JavaScript events. The following code describes a callback, a variable that stores an object by the query of a selector, and finally, adds an “event listener” when an “event” (such as a click) occurs to fire off the callback, which takes the properties of the object clicked and passes it to the callback function.

var handleClick = function (event) {
    // do something!
};
var button = document.querySelector('#big-button');
button.addEventListener('click', handleClick);

$('.btn').click(function () {
    // do something
});

Whew!