Having a hard time understanding exactly what .innerText does

So, I’m learning about basically bringing in a html element into javascript with document.getElementById

and to my understanding using .innertext in javascript is simply to be able to put text into the element without actually typing in anything in html? I’m trying to understand this a little better before I move on because I’m sure I’ll get lost if I don’t grasp this.

thanks everyone!

Not really sure what the question is?

There are two ways to use innerText.

One is to set the text of the element. Assuming you have an h1 element with id='h1Elem, then you can write the following to change its value.

document.getElementById('h1Elem').innerText = 'New Text Goes Here'

You can also use it to get the current value of an element’s text. Assume you have the following HTML:

  <h1 id="myH1">Hello World!</h1>

I can get the text value of the h1 element by:

const h1Text = document.getElementById('myH1').innerText;
console.log(h1Text); // displays Hello World!