Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

The id attribute

Because you’ve already used ids on <a> elements, and because you already know how to use a class attribute, you’re not going to have to learn much to use the id attribute. Say you have a footer on your page. There’s usually only one footer on any page, so that sounds like the perfect candidate for an id. Here’s how you’d add the identifier “footer” to a paragraph that contains the footer text:

image with no caption

Giving an element an id is similar to adding an element to a class. The only differences are that the attribute is called “id”, not “class”, an element can’t have multiple ids, and you can’t have more than one element on a page with the same id.

There are no Dumb Questions

Q:

Q: What’s the big deal? Why do I need an id just to prove something is unique on the page? I could use a class exactly the same way, right?


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint