Single Choice Easy

QWhat would the following JavaScript code produce?

<p id="Element">Head</p>
function myFunction() 
{
   var x = document.getElementsByTagName("P").namedItem("Element");
   alert(x.innerHTML);
}

ID: #5099 Javascript DOM & Event Handling MCQ 118 views
Question Info
#5099Q ID
EasyDifficulty
Javascript DOM & Event Handling MCQTopic

Choose the Best Option

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

  • A Head
  • B Element
  • C Error
  • D Undefined
Correct Answer

Explanation

The element with the given ID or name is returned by the namedItem() method in an HTMLCollection.
The same outcome can be achieved using a shortcut way.

Share This Question

Challenge a friend or share with your study group.