jQuery Selectors

One of the most common activities of any JavaScript programmer, is to select elements on a page, to make some change to it for whatever reason they have. Selecting an element in JavaScript is not easy to say the least. You have to know the individual element’s id attribute to be able to select it.

jQuery selectors make selecting elements very easy. You can select elements using jQuery based on many different element attributes.

The following attributes can be used to select one or more elements using just one line of code:

Id, class, type, attributes values in attributes. There are many more that you will see as you move through this tutorial.

The jQuery object selector method comes in two forms.

First there is the un-shortened method:

jquery()

Then there is the shortcut method:

$()

Because it is easier to use and because you will be using it so often, I suggest that you get used to using the shortcut method. This method will return any element or elements from a page that exists based on the selection attributes that you pass it.

The beauty of this is that, as you will see as you work through this tutorial, you can affect one or many elements on a page, based on your selection attributes.

No comments:

Post a Comment