MCQ Single Best Answer Easy

QWhat would the following JavaScript code produce?

function counth2()
{  
    var totalh2=document.getElementsByTagName("h2");  
    alert("totalh2.length);  
}  
<h2>hello</h2>  
<h2>hello</h2>

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

Choose the Best Option

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

  • A 0
  • B hello
  • C h2
  • D 2
Correct Answer: Option D

Explanation

All elements with the supplied tag name are returned by the document.getElementsByTagName() function.

Share This Question

Challenge a friend or share with your study group.