MCQ Single Best Answer Easy

QWhat would the following JavaScript code produce?

<head id="myHead">
  <title>My title</title>
</head>
<p id="demo"></p>
<script>
function myFunction() 
{
   var x = document.head.id;
   document.getElementById("demo").innerHTML = x;
}
</script>

ID: #5101 Javascript DOM & Event Handling MCQ 150 views
Question Info
#5101Q ID
EasyDifficulty
Javascript DOM & Event Handling MCQTopic

Choose the Best Option

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

  • A demo
  • B myHead
  • C error
  • D undefined
Correct Answer: Option A

Explanation

The current document's <head> element is returned via the head attribute. The head's id is returned by the id attribute.

Share This Question

Challenge a friend or share with your study group.