Home > Web Front-end > JS Tutorial > The difference between getElementById().innerHTML and getElementById().value will be explained to you in detail

The difference between getElementById().innerHTML and getElementById().value will be explained to you in detail

亚连
Release: 2018-05-19 14:49:39
Original
2629 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template