MCQ Single Best Answer Not Set

QWhich method in javascript is used to acquire an HTML element?

ID: #4847 Basic JavaScript MCQ 185 views
Question Info
#4847Q ID
Not SetDifficulty
Basic JavaScript MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A getElementbyId()
  • B getElementsByClassName()
  • C Both A & B
  • D None of the above
Correct Answer: Option C

Explanation

There are several ways to get a reference to an HTML element in JavaScript:
getElementById():
This method is used to get a reference to an element with a specific id.
For example:
let element = document.getElementById('my-element');
getElementsByClassName():
This method is used to get a list of elements with a specific class name.
For example:
let elements = document.getElementsByClassName('my-class');

Share This Question

Challenge a friend or share with your study group.