Beyond the DOM with jQuery utility functions

This lesson covers

  • The jQuery properties
  • Avoiding conflict between jQuery and other libraries
  • Array manipulation functions
  • Extending and merging objects
  • Parsing different formats
  • Dynamically loading new scripts

Up to this point, we’ve spent a number of lessons examining the jQuery methods that operate upon a set of DOM elements selected by using the $() function. But you may recall that way back in lesson 1 we also introduced the concept of utility functions—functions namespaced by jQuery/$ that don’t operate on a jQuery object. These functions could be thought of as top-level functions except that they’re defined on the $ instance rather than window, keeping them out of the global scope. Generally, these functions either operate upon JavaScript objects other than DOM elements or perform some non-object-related operation (such as an Ajax request or the parsing of a XML string).

In addition to functions, jQuery provides some properties (sometimes referred to as flags) that are defined within the jQuery/$ namespace. Some of these properties are meant for internal use only, but because they’re documented in the jQuery API website and some plugins use them, we thought that they’re worth a mention for the most curious among you.

You may wonder why we waited until this lesson to introduce these functions and properties. We had two reasons:

  • We wanted to guide you into thinking in terms of using jQuery methods rather than resorting to lower-level operations.
  • Because the methods take care of much of what you want to do when manipulating DOM elements on the pages, these lower-level functions are frequently most useful when writing the methods themselves (as well as other extensions) rather than in page-level code. (We’ll tackle how to write your own jQuery plugins in lesson 12.)

In this lesson, we won’t talk about the utility functions that deal with Ajax because we’ll dedicate the whole of lesson 10 to them. We’ll start out with those properties we mentioned.


by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *