SoFunction
Updated on 2025-04-06

The difference between getElementById.innerHTML and getElementById.value

Simply put: use value for form, use innerHTML for inserting characters

For example <input type="text" value=""  />

Only tags with value attribute can be usedgetElementById("jb51").value
Like <div >12345</div>

This kind of tag without value attribute is usedgetElementById("jb51").innerHTML

You can use() to get an element with an id on the page
Then access the attributes of this element, such as value

When an element has a value attribute, its value will have a value
Example 1
<input type="text" value="hello"/>
Such an element, when you use ("txt1").value, you can get its value, that is, the string "hello".

If an element has no value, it cannot be retrieved when using().value. This is natural, how to access things without them?
For example, a div tag may not necessarily have a value value.

innerHTML
This refers to the content of the element
Example 2

An element has a start mark and an end mark such as

<label >this is a label</label>

When you use ("lb1").innerHTML, you can get the content between <label> and </label>, that is, "this is a label".