Handling Events

jQuery helps you add event listeners to the objects you select. These are similar to the DOM events but are somewhat easier to work with and provide greater flexibility. In addition, jQuery defines its own events for animating the display of information. These animations make your page more appealing to users.

Let’s start by looking at the .ready() function. This is a key jQuery event that can be used to wrap code you want to execute when the DOM has fully loaded and is ready for work. You write this event as $(document).ready(function(){...}). There is also a shorthand version of this method written as $(function(){...}). The following shows an example.

$(document).ready(function () {  $('#footer').css('background-color', ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.