1. The id Attribute
The id attribute specifies a globally unique identifier for an HTML element. Within an entire HTML document, no two elements can share the same id value.
- Targeted in CSS using the hash symbol:
#exam-timer { color: red; }. - Targeted in JavaScript via:
document.getElementById("exam-timer"). - Used for URL fragment page bookmarks:
.
2. The class Attribute
The class attribute defines a reusable styling or behavioral classification. Multiple elements can share the same class name, and a single element can have multiple classes separated by spaces.
- Targeted in CSS using the dot symbol:
.btn-primary { background: blue; }. - Targeted in JavaScript via:
document.querySelectorAll(".question-card").