Home > Article > Web Front-end > The difference between getElementById().innerHTML and getElementById().value will be explained to you in detail
This article mainly introduces the difference between getElementById().innerHTML and getElementById().value. Friends in need can refer to it
Simply put: use value for forms and innerHTML for inserting characters
For example,
Only tags with value attributes can be usedgetElementById("jb51").value
Like
12345
For tags without value attributes, use getElementById("jb51").innerHTML
You can use document.getElementById() 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
Such an element, when you use document.getElementById("txt1 ").value, you can get its value, that is, the string "hello".
If an element does not have a value, it cannot be obtained when using document.getElementById().value. This is a matter of course, how can you access something you don’t have?
For example, a p mark does not necessarily have a value.
innerHTML
This refers to the content in the element
Example 2
An element has a start tag and an end tag such as
When you use document.getElementById("lb1").innerHTML you can get the content between , that is "this is a label".
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
jsInstance of executing a function after the code is delayed for a certain period of time
JS simply implements the floating window
Avalonjs implements the simple shopping cart function
The above is the detailed content of The difference between getElementById().innerHTML and getElementById().value will be explained to you in detail. For more information, please follow other related articles on the PHP Chinese website!