What will be the output of the following JavaScript code? [code] <p>1</p> <p>2</p> <p>3</p> function myFunction() { var x = document.getEle

What will be the output of the following JavaScript code?
Code:
<p>1</p>
<p>2</p>
<p>3</p>
function myFunction() 
{
    var x = document.getElementsByTagName("P").item(0);
    alert(x.innerHTML);
}
A. 1
B. 2
C. 3
D. Error
 
Answer: a
Explanation: Item object Returns the element at the specified index in an HTMLCollection. The function gets the HTML content of the first <p> element of the document.
 

Tìm kiếm

Back
Top