SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: html element's id attribute
-
Jan 13, 2009, 23:46 #1
- Join Date
- Feb 2007
- Posts
- 71
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
html element's id attribute
Hi, gurus,
I recently recalled an question in my mind for a long time, is the id attribute interpreted as a CSS style or an identification of the html element only?
ie: <p id="para">Test Paragraph</p>
Is "para" an identification of <p> element or is it a CSS style?
Thanks, Charlie123
-
Jan 14, 2009, 00:02 #2
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
It is part of the HTML and acts as an anchor point in the page that you can link to even where there is no CSS or JavaScript that references it.
<a href="#para">Go to Test Paragraph</a>Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jan 14, 2009, 00:46 #3
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The id attribute provides a unique identifier for a single element. In your example, 'para' uniquely identifies that particular <p> element and there must not be any other element with id="para" in the same document.
IDs have three main uses:
- They specify the target of a fragment identifier in a link, e.g., <a href="page.html#para">link</a>.
- They provide a means for targeting individual elements via CSS selectors: #para {...}
- The provide a means for targeting individual elements via JavaScript: document.getElementById("para");
Birnam wood is come to Dunsinane
-
Jan 14, 2009, 18:34 #4
- Join Date
- Mar 2007
- Posts
- 182
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
id's are good to indentify a particular element on a document so that you can apply styles to that particular element in your css file that you link to the document / or embed within the document itself. If you want to apply a style to multiple elements, you could use classes in your html. Classes can be applied more than once unlike the id.
Jaysone
Bookmarks