THE ID ATTRIBUTE
The id attribute can be used to uniquely identify any element within a page or style sheet. There are twoprimary reasons that you might want to use an id attribute on an element:
❑ If an element carries an id attribute as a unique identifier it is possible to identify just that element and its content (perhaps you want to link to a specific point in a document, to select one specific element’s content, to associate a CSS style with a particular element, or identify that element using a script).
❑ If you have two elements of the same name within aWeb page or style sheet, you can use the id attribute to distinguish between elements that have the same name (this is very likely, when you think most pages will contain at least two or more paragraphs of text).
The syntax for the id attribute is as follows (where string is your chosen value for the attribute):
id="string"
For example, the id attribute could be used to distinguish between two paragraph elements, like so:
<p id="accounts">This paragraph explains the role of the accounts
department.</p>
<p id="sales">This paragraph explains the role of the sales
department.</p>
Note that there are some special rules for the value of the id attribute; it must:
❑ Begin with a letter (A–Z or a–z) and can then be followed by any number of letters, digits (0–9),
hyphens, underscores, colons, and periods (you may not start the value with a digit, hyphen, underscore, colon, or period).
❑ Remain unique within that document; no two attributes may have the same value within that XHTML document. Before the id attribute was introduced, the name attribute served a similar purpose in HTML documents, but its use was deprecated in HTML 4.01, and now you should generally use the id attribute in XHTML
documents. If you need to use the name attribute it is available in Transitional XHTML, but not Strict XHTML
0 comments:
Post a Comment