Classes and ids

Inside your XHTML document, you’ll mark up your content by breaking it down into those meaningful chunks. From there, you’ll still need to identify those pieces of content where you want to change their presentation or behavior. For that, you’ll primarily use two attributes: class and id. These attributes can be used by both CSS and JavaScript; a CSS style sheet uses those attributes as part of rules to define the appearance of a page, and the JavaScript file can use those attributes in code that affects the behavior of elements on the page.

✓ Tip

  • Having trouble remembering when to use # versus . in your CSS because you can’t recall which one goes with class and which with id? Here’s our method: an id can be on any given page ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.