What will be the output of the following JavaScript code? [code] function counth2() { var totalh2=document.getElementsByTagName("h2");

What will be the output of the following JavaScript code?
Code:
function counth2()
{  
    var totalh2=document.getElementsByTagName("h2");  
    alert("totalh2.length);  
}  
<h2>hello</h2>  
<h2>hello</h2>
A. 0
B. hello
C. h2
D. 2
 
Answer: d
Explanation: The document.getElementsByTagName() method returns all the element of specified tag name. The above code counts the total number of specific tags.
 

Tìm kiếm

Back
Top