O'Reilly logo

Beginning JavaScript® and CSS Development with jQuery by Richard York

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Answers to Exercises

  1. CSS and XPath are both acceptable answers.

  2. parents()

  3. prev()

  4. find() or children(), depending on where the element exists in the hierarchy: children() can be used for immediate children of the element, and find() can be used for either immediate children or descendents.

  5. not()

  6. You would use the eq() method and supply the position of the element within the selection offset from zero as the first argument.

  7. siblings(), prev(), next(), prevAll(), nextAll()

  8. Using the add() method

  9. Yes

  1. It is not possible to attach multiple events of the same type to the same element using the traditional event model; however, some very keen programming creativity could overcome this limitation, if one were so inclined.

  2. The ability to attach multiple events of the same type to the same element. There are other items addressed in the W3C's API, but I consider this to be the biggest.

  3. In the traditional event model, and Microsoft's event model, each event is named with an on prefix, for example, onclick, onsubmit, onchange, and so on. In the W3C's event model, the on prefix is dropped, but the names are otherwise the same.

  4. The bind() method. It has a shorter name, and it drops the third useCapture argument used in the W3C's Event API. Bonus points if you referred to the useCapture argument as "mostly useless."

  5. You can use the trigger('focus') method, or you can call the focus() method without any arguments. Bonus points if you looked in Appendix D and discovered the triggerHandler() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required