HTML and CSS Reference
In-Depth Information
//
It is possible to apply specific styles to every second row purely through CSS:
tr:nth-child(even) {
background-color: #f8f8f8;
}
Using classes for reasons other than CSS matching does not go against the spirit of the
HTML5 specification. The specification states that classes are one way that elements can
be extended, thereby effectively creating a new type of element.
The fourth basic way to select elements is based on their ID. Any element can be given an
ID using the id attribute.
ID names are arbitrary, just as class names are, but ID names must be unique within a doc-
ument.
//
HTML5 has relaxed the rules on the values that can be used for IDs. The only
rules now are that they must be unique in a document, and cannot be an empty
string or contain spaces. The rules for class names are identical.
An element can be given an ID as follows:
<table id='tblTasks'>
Once an element has been given an ID it can be selected with the following criteria:
> $('#tblTasks')
(Note the “#” sign at the start of the selection criteria.)
The last way of selecting elements is via jQuery filters. If you are familiar with CSS, these
may look the same as CSS pseudo-classes, and they essentially serve the same purpose.
Suppose we want to find the first row in a table . We could add a class to the row, but if the
table was re-ordered we would need to make sure this was updated. We could also select all
rows from the table into an array and choose the first element, but this is inefficient. With
filters we can use the following selection criteria:
> $('tr:first')
 
Search WWH ::




Custom Search