id Attribute
The id attribute is used to give a particular element a unique identifier. It is used for a wide variety of purposes: internal links, some image maps, id selectors, and, in JavaScript, to access elements with the document.getElementById(). See w3schools for complete rules. Know the following (I don't care about ':' and '.' in ids):
- There should only be one element on a page with a given id (they must be unique)
- Case-sensitive
- Cannot contain spaces
- Must begin with a letter
- After the first letter character, can contain, underscore '_', hyphen '-', numbers 0-9, and letters.
Examples:
As it appears in an element
<h1 id="mainHeading">Main Heading</h1>
<p id="paragraph22"> .. </p>
Good Examples
id="main"
id="paragraph2"
id="intro_paragraph"
id="Bear-Map02"
Incorrect ids (click them for reason)
id="_main_"
id="#main"
id="2ndParagraph"
id="--intro--"
id="intro paragraph"
Back to Knowledge Dump