Which JavaScript method selects an element by its id?
-
A
querySelector()
-
B
getElementById()
Correct answer
-
C
getElementsByClassName()
-
D
select()
Correct answer
B. getElementById()
11 views
Explanation
document.getElementById() selects an element by id. Source: Standard JavaScript content (FBISE-aligned).
Reference
Asked in: Matric,FBISE
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ