O'Reilly logo

jQuery Essentials by Troy Miles

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating selectors

One of the things that makes jQuery selectors so cool and easy to learn is that they are based on the selectors used by CSS; this is not the case with the browser methods. So, if you already know how to create CSS selectors, you will have no trouble learning about jQuery selectors. If you don't know about CSS selectors, don't worry; jQuery selectors are still easy to learn, and knowing about them will give you a head start on learning about CSS selectors.

ID selectors

The first kind of selector we will look at is the ID selector. It begins with a hash sign and is followed by the same string used in the ID attribute of the desired element. Take a look at this example:

<div id="my-element"></div>
var jqObject = $("#my-element"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required