The $() function
No matter which type of selector we want to use in jQuery, we always start with the same function: $()
. This function typically accepts a CSS selector as its sole parameter, and serves as a factory, returning a new jQuery object pointing to the corresponding elements on the page. Just about anything that can be used in a stylesheet can also be passed as a string to this function, allowing us to apply jQuery methods to the matched set of elements.
Tip
Making jQuery play well with other JavaScript libraries
In jQuery, the dollar sign $
is simply an "alias" for jQuery
. As a $()
function is very common in JavaScript libraries, conflicts could arise if more than one of these libraries were being used in a given page. We can avoid such conflicts by replacing every instance of $
with jQuery
in our custom jQuery code. Additional solutions to this problem are addressed in Chapter 10, Advanced Events.
The three primary building blocks of selectors are tag name , ID , and class . They...