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

Compound Events


Most of jQuery’s event-handling methods directly respond to native JavaScript events. A handful, however, are custom handlers added for convenience and cross-browser optimization. One of these, the .ready() method, we have discussed in detail already. The .toggle() and .hover() methods are two more custom event handlers; they are both referred to as compound event handlers because they intercept combinations of user actions, and respond to them using more than one function.

Showing and Hiding Advanced Features

Suppose that we wanted to be able to hide our style switcher when it is not needed. One convenient way to hide advanced features is to make them collapsible. We will allow one click on the label to hide the buttons, leaving the label alone. Another click on the label will restore the buttons. We need another class to handle the hidden buttons:

.hidden {
  display: none;
}

We could implement this feature by storing the current state of the buttons in a variable, and...