Appendix A

Exercise Answers

Chapter 2

  1. CSS and XPath are both acceptable answers.
  2. parents()
  3. prev()
  4. children() for immediate descendants and find() for any elements in the descendant hierarchy
  5. not()
  6. eq()
  7. siblings(), prev(), next(), prevAll(), nextAll()
  8. add()

Chapter 3

  1. You can use the mouseover() or on('mouseover') method. If you use deprecated methods, in addition, you can use bind('mouseover') or live('mouseover').

    Extra Credit: Use the hover() method.

  2. The on() method.
  3. The property is used to check to see which descendant element has received the event. The event then bubbles up from that element to the element that the event handler is attached to.
  4. Provide a selector argument to the on() method describing the element you want the event to apply to on the parent or container element that contains the elements you want the event to apply to. This can also be the document object.
  5. Naming an instance of an event handler can be done by applying the event name, a dot, and then the namespace you want to use. You can apply multiple event names by repeating the same process.
  6. The off() method.
  7. Yes.
  8. You can use either click() with no arguments or trigger('click').
  9. A custom event handler begins with any event name not already in use in JavaScript; you can attach a custom event handler using that name using the on() method. The trigger() method can be used to fire the custom event handler, as well as to send custom data to the event handler.

Chapter 4

  1. One possibility: ...

Get Web Development with jQuery now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.