??™).
An id attribute has several uses:
??? As a style sheet selector (which has a higher specificity than other selectors)
??? As a target anchor for hyperlinks
??? As a means to reference a unique element using DOM scripting
The class attribute assigns a class name or multiple class names separated by a space.
The same class name can be applied to multiple elements on the page. Class naming conventions
are much looser than for IDs. You have letters, numbers, the hyphen, and most of the
Unicode character set at your disposal. However, I recommend sticking with letters, numbers,
and hyphens??”anything else will be confusing.
nTip Use class names that help to describe the content in a semantic way. The name ???bluetext??? isn??™t very
helpful if you decide to change the design to green. Use names such as ???callout??? or ???caption??? to more accurately
describe things.
As you build your application, it??™s important to know when to use each attribute. The
quickest rule is this: if there is and will only ever be one of a particular type of element, use an
id. Otherwise, you should use a class name.
Here??™s a quick example:
General
- Groceries
- Dry cleaning
- Buy books
Programming
CHAPTER 2 n HTML, CSS, AND JAVASCRIPT 18
- Finish project
- Make cool examples
- Write article for site
As you can see, I encapsulated all my lists in a