getElementById (). Difference between innerHTML and getElementById (). Value _ Basics

Source: Internet
Author: User

Because there are always novice friends to ask this question, so the cloud-Habitat community small compilation of methods needed friends.

In simple terms: Table single value, insert character with innerHTML

such as <input type= "text" value= "" id= "jb51"/>

A label with the Value property can be usedgetElementById("jb51").value
Like <div id= "jb51" >12345</div>

This label without the value attribute is usedgetElementById("jb51").innerHTML

You use document.getElementById () to get to the page with an ID element
And then access the attributes of this element, such as value

When an element has a value attribute, its values are valued
Example 1
<input type= "text" id= "txt1" value= "Hello"/>
Such an element, when you use document.getElementById ("Txt1"). Value, you can get its value, that is, "hello" this string.

If an element has no value, then the document.getElementById () value is not available. It is taken for granted that there is no such thing as how to access?
A div tag, for example, does not necessarily have a value.

InnerHTML
This refers to what is in the element
Example 2

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

<label id= "LB1" >this is a label</label>

When you use document.getElementById ("LB1"). innerHTML can take the content between <label> and </label>, that is, ' this is a label '.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.