-
Book Overview & Buying
-
Table Of Contents
Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques
No matter which type of selector we want to use in jQuery—be it CSS, XPath, or custom—we always start with the dollar sign and parentheses: $()
As mentioned in Chapter 1, the $() function removes the need to do a for loop to access a group of elements since whatever we put inside the parentheses will be looped through automatically and stored as a jQuery object. We can put just about anything inside the parentheses of the $() function. A few of the more common examples include:
A tag name:
.
$('p') gets all paragraphs in the document.
An ID:
.
$('#some-id') gets the single element in the document that has the corresponding some-id ID.
A class:
.
$('.some-class') gets all elements in the document that have a class of some-class.
Making jQuery Play Well with Other JavaScript Libraries
In jQuery, the dollar sign $ is simply shorthand for jQuery. Because a $() function is very common in JavaScript libraries, conflicts could arise if more than one of these libraries...
Change the font size
Change margin width
Change background colour