Book Image

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Book Image

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Overview of this book

Table of Contents (18 chapters)
Learning jQuery
Credits
About the Authors
About the Reviewers
Preface

Chapter 3. Events—How to Pull the Trigger

 

Getting bigger, pull the trigger

 
 -- Devo, “Puppet Boy”

JavaScript has several built-in ways of reacting to user interaction and other events. To make a page dynamic and responsive, we need to harness this capability so that we can, at the appropriate times, use the jQuery techniques we have learned so far. While we could do this with vanilla JavaScript, jQuery enhances and extends the basic event handling mechanisms to give them a more elegant syntax while at the same time making them more powerful.

Performing Tasks on Page Load

We have already seen how to make jQuery react to the loading of a web page. The $(document).ready() event handler can be used to fire off a function’s worth of code, but there’s a bit more to be said about it.

Timing of Code Execution

In Chapter 1, we noted that $(document).ready() was jQuery’s way to perform tasks that were typically triggered by JavaScript’s built-in onload event. While the two have a similar effect...