The jQuery() Function
The jQuery() function (a.k.a.
$()) is the most important one in the
jQuery library. It is heavily overloaded, however, and there are four
different ways you can invoke it.
The first and most common way to invoke $() is to pass a CSS selector (a string) to
it. When called this way, it returns the set of elements from the
current document that match the selector. jQuery supports most of the
CSS3 selector syntax, plus some extensions of its own. Complete details
of the jQuery selector syntax are in jQuery Selectors.
If you pass an element or a jQuery object as the second argument to
$(), it returns only matching
descendants of the specified element (or elements). This optional second
argument value defines the starting point (or points) for the query and
is often called the context.
The second way to invoke $() is
to pass it an Element, Document, or Window object. Called like this, it
simply wraps the element, document, or window in a jQuery object and
returns that object, allowing you to use jQuery methods to manipulate
the element rather than using raw DOM methods. It is common to see
jQuery programs call $(document) or
$(this), for example. jQuery objects
can represent more than one element in a document, and you can also pass
an array of elements to $(). In this
case, the returned jQuery object represents the set of elements in your
array.
The third way to invoke $() is to pass it a string of HTML text. When you do this, jQuery creates the HTML element (or elements) ...