Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [476]

By Root 5769 0
filters allow you to select HTML elements where a given attribute is in a given relationship with a value. Table 21-4 lists all attribute filters supported in jQuery.

Table 21-4. Attribute Filters

Filter

Description

[attribute]

Returns all elements that have the specified attribute. This filter selects the element regardless of the attribute’s value.

[attribute = value]

Returns all elements where the specified attribute (if present) is set to the specified value.

[attribute != value]

Returns all elements whose specified attribute (if present) has a value different from the given one.

[attribute ^= value]

Returns all elements whose specified attribute (if present) has content that starts with the given value.

[attribute $= value]

Returns all elements whose specified attribute (if present) has content that ends with the given value.

[attribute *= value]

Returns all elements whose specified attribute (if present) has content that contains the given value.

Attribute filters can also be concatenated by simply placing two or more of them side by side, as in the following example:

var elems = $("td[align=right][valign=top]");

The returned set includes all elements where the horizontal alignment is right and the vertical alignment is top.

The next expression, which is much more sophisticated, demonstrates the power and flexibility of jQuery selectors, as it combines quite a few of them:

#Table1 tr:nth-child(3n+1):has(td[align=right]) td:odd

It reads as follows:

Within the body of element Table1, select all elements at positions 1, 4, 7, and so forth. Next, you keep only table rows where a element exists with the attribute align equal to the value of right. Furthermore, of the remaining rows, you take only the cells on columns with an odd index.

The result is a wrapped set made of elements.

Finally, a couple more filters exist that are related to the visibility of elements. The :visible filter returns all elements that are currently visible. The :hidden filter returns all elements that are currently hidden from view. The wrapped set also includes all input elements of type hidden.

Form Filters


A special family of filters exists for HTML input elements. Table 21-5 lists all of them.

Table 21-5. Input Field Filters

Filter

Description

:input

Returns all elements that have a role in collecting input data

:text

Returns all input elements whose type attribute is text

:password

Returns all input elements whose type attribute is password

:checkbox

Returns all input elements whose type attribute is checkbox

:radio

Returns all input elements whose type attribute is radio

:submit

Returns all input elements whose type attribute is submit

:reset

Returns all input elements whose type attribute is reset

:image

Returns all input elements whose type attribute is image

:button

Returns all input elements whose type attribute is button

:file

Returns all input elements whose type attribute is file

:hidden

Returns all input elements whose type attribute is hidden

:enabled

Returns all input elements that are currently enabled

:disabled

Returns all input elements that are currently disabled

:checked

Returns all input elements that are currently checked

:selected

Returns all input elements that are currently selected

The :input filter, in particular, refers to all logical input elements you might find within a page form and is not limited solely to the elements. In fact, it also picks up