SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    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

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    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="^$">

  3. #3
    SitePoint Author silver trophybronze trophy

    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:
    1. They specify the target of a fragment identifier in a link, e.g., <a href="page.html#para">link</a>.
    2. They provide a means for targeting individual elements via CSS selectors: #para {...}
    3. The provide a means for targeting individual elements via JavaScript: document.getElementById("para");
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Charlie123 View Post
    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
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •