Appendix A. Getting Started with jQuery

For years JavaScript programmers have been dealing with the myriad idiosyncrasies of the DOM (Document Object Model) API. Many people created helper functions that abstracted particular operations so that they worked across all browsers, and a few of the best abstractions became polished enough to become generally useful for a wide range of applications. The jQuery library is a lightweight, cross-browser JavaScript library that replaces the ugly parts of the DOM API with a clever CSS selector-based API that makes quick work of most tasks.

jQuery is excellent for slicing and dicing HTML, but it also works very well on XML documents. Because XMPP stanzas are just XML document fragments, jQuery makes manipulating XMPP much easier than using the raw DOM APIs.

Strophe itself was partially inspired by the function chaining, use of callbacks, and plug-in architecture in jQuery, and so the two libraries fit together quite naturally.

If you haven't used or seen jQuery before, this appendix teaches you the basics and gives you the background you need to use jQuery effectively for your own XMPP applications. The jQuery library also provides many other useful functions for web programming, like AJAX requests and animations, but these are not covered here because they are not used in the book.


You can find the jQuery library on the Web at jQuery's web site also contains tutorials, reference documentation, examples, and a long ...

Get Professional XMPP Programming with JavaScript® and jQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.