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', ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access