JavaScript Learning note Document and innerHTML, InnerText

Source: Internet
Author: User

The most common object that we use in JavaScript is the Document object

Document object: Each HTML document that is loaded into the browser becomes the document object. We can use the Document object to access the elements in the HTML.

document.getElementById ()

To get the corresponding value by ID

1. Text box

If you want to get the value of a drop-down list box

2. Drop-down selection box



Second, Document.getelementsbyname

This method is roughly the same as getElementById, except that getElementById returns an object, and Getelementsbyname returns a list, This method is used in a text box or checkbox with the same name (see the previous article List select all feature)


Third, Document.getelementbytagname

getElementsByTagName gets a collection under a specified label, not because the label is placed in the range of the collection (for example, to write a form form, which also has the element that the input tag represents, it is also counted in the Elements collection). , it can be found through getElementsByTagName)


The above three methods combined with the use of our web page production is a more common step, so to understand the above relevant knowledge

Iv. Other document There are also some methods and objects set

document.write: Write an HTML expression or JavaScript code to a document

Sometimes we use the document.write () method when we dynamically create HTML tags.

Document.forms[]: Returns a reference to all the form references in a document, such as we want to get the value of a text box inside a form, we can do this:

V. About InnerText and innerHTML

InnerText and innerHTML can add the corresponding information to the tag body, such as we define a <span id= "feedback" ></span>, and the information we return can be dynamically loaded to put in this <span > Inside, here we can use innertext or innerHTML. Today in the project, found a problem, is that Firefox does not support the InnerText property, the solution is to change the innertext to innerHTML.

JavaScript Learning note Document and innerHTML, InnerText

Related Article

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.