Which method is used to select an element by its ID in JavaScript?

  • getElementByTag
  • getElementById
  • getElementByClass
  • querySelector
The correct method to select an element by its ID in JavaScript is getElementById. This method retrieves an element by its unique ID attribute. The other options do not select elements by their IDs.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *