12.3. Selecting Elements

jQuery's strength is the ease with which you can select and manipulate elements on the page. You have used a selector method already to select all <div> elements that have an ID of div1:

$("#div1").html("hello jQuery");

jQuery supports many different ways to select an element or elements that should meet all but the most awkward requirements. Table 12-1 lists examples of other selection methods you might want to use.

Table 12.1. Example Selection Methods
SelectorSelected
$("#div1")Selects a <div> with an ID of div1.
$("div")Selects all <div>s.
$("div.standardDiv")Selects all <div>s with a class of standardDiv.
$(".standardDiv")Selects all elements with a class of standardDiv.
$("#div4 #div5")Selects a <div> with an ID of ...

Get Introducing .NET 4.0: with Visual Studio 2010 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.