Elements by tagname not working

what am i doing wrong here?

<body>
    <div></div>


<script>

var x = 5, y = 2;
  
  x += y;

  document.getElementsByTagName('div').innerHTML = x;



</script> 
    

“The Element.getElementsByTagName() method returns a live HTMLCollection of elements with the given tag name.”

The live collection it returns is not a single element but rather like an array:

After reading the above documentation how do you think you would access the <div>?

1 Like

Ya, Makes sense now.This is just my second day of understanding JS in depth.Thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.