Inner html not working

Question:
inner html attribute is not running

Current behavior:
it shows no change
Desired behavior
it should show change
Repl link:

43_insertionMethod

code snippet
 let a= document.getElementsByTagName('div')
a.innerHtml = a.innerHtml+"<b>Hello</b>"

The getElementsByTagName function returns not one element, but a list of elements, that is, all elements of the page with the div tag are returned at once.

You can use innerHTML only for one element, not for a list of elements.

You can get one of the elements using this code:

const divs = document.getElementsByTagName('div') // returns a list
const a = divs[0] // 0 - index of one of the list items

Next to object a you can use innerHTML

a.innerHTML += "<b>Hello</b>"
3 Likes

It is not innerHtml, but innerHTML.

And yeah, getElementsByTagName returns an array of all the elements, not a single one.