Which JavaScript method is used to select an HTML element by its ID?
- querySelector()
- getElementById()
- getElementsByClassName()
- getElementsByTagName()
Answer: getElementById()
getElementById('id') returns the element with specified ID (case-sensitive). querySelector() uses CSS selectors for more flexibility. getElementsByClassName/TagName return collections. DOM manipulation is core to interactive web development and frequently tested in programming sections of exams.