The getElementById () method of the html DOM document Object, domgetelementbyid
The getElementById () method returns a reference to the first object with the specified ID.
Syntax:
document.getElementById(id)
The html dom defines multiple methods for
Definition and usageThe getElementById () method returns a reference to the first object that owns the specified ID.Grammardocument.getElementById (ID)DescriptionThe HTML DOM defines a variety of methods for finding elements, with the exception of
Definition and usageThe getElementById () method returns a reference to the first object that owns the specified ID.Grammardocument.getElementById (ID)DescriptionThe HTML DOM defines a variety of methods for finding elements, with the exception of
As follows, there is a text control with name = "txtversion:
Based on the above information, we need to use js to obtain the value in its control. We write as follows:VaR strversion = Document. getelementbyid ("txtversion"). value;The above code
When writing JavaScript, we will often use the document. getelementbyid () method. This long string is easy to write errors, and getelementbyid is case sensitive.
Prototype. one method advocated in JS is to use $ () for short. With the following
"intro">hello world!10. cat connection file or standard input and print. This command is often used to display the contents of a file,Or connect several files together to displayOr read the content from the standard input and display it, often in
Web standards can access any of the tags in the document through getElementById (), Getelementsbyname (), and getElementsByTagName ().(1) getElementById ():getElementById () can access a specific element in the document, as the name implies, by
This time, we will introduce the relevant content of DOM nodes. According to the explanation in W3CSchool, DOM stipulates that the entire document is a document node, and each HTML tag is
This time, we will introduce the relevant content of DOM
In the Web standard, you can use getelementbyid (), getelementsbyname (), and getelementsbytagname () to access any tag in the document.
(1) getelementbyid ():
Getelementbyid () can access a specific element in the document. As the name suggests,
What we're talking about here. Gets the node that contains the element node, the attribute node, and the text node. In general, we are able to manipulate HTML elements through the DOM. ForTo do this, you must first find the element. It provides a
In the Web standard, you can use getelementbyid (), getelementsbyname (), and getelementsbytagname () to access any tag in the document.
(1) getelementbyid ():
Getelementbyid () can access a specific element in the document. As the name suggests,
It provides a convenient and simple method and properties for locating nodes so that we can quickly operate on the nodes.respectively: getElementById (), getElementsByTagName (), Getelementsbyname (), getattribute (), SetAttribute (), and
One, variableJavascript has five basic data types number, String, boolean, undefined, null a composite type: ObjectSecond, using the getElementById method to obtain the elementWay One:Here the element, refers to the HTML tag, through the built-in
I have roughly translated some of the articles, may have misunderstood the place, please correct me. It is worth mentioning that the debate in the comments section is also worth seeing.
Feature Detection
At first, the front-end engineers objected
DOM is the Document Object Model: the purpose of DOM creation is to reconstruct the entire HTML page and add, change, or rearrange projects on the page. Look at the simplest html file: & amp; lt; html & amp; gt; & amp; lt; head & amp; gt; & amp;
Such a problem arises in the course of learning the getElementById () method, and is to be recorded. Before we analyze the problem, we might as well get to know the getElementById () method first. getElementById () method, takes a parameter; Gets
getElementById (): The purpose of the method is to look for an element with a given id attribute worth:element = document.getElementById (ID);This method returns a node with the given ID attribute that is worth the element. If such an element does
DOM Access Node Nodes instance Tutorial
Here you can access each node of the HTML file.
Access nodeYou can use a node in three aspects:
1. By using the getElementById () method
2. By using the getElementsByTagName () method
3. Through the nodes
DOM Tutorial: HTML dom Access Nodes
Here you can access each node of the HTML file.
Access nodeYou can use a node in three aspects:
1. By using the getElementById () method
2. By using the getElementsByTagName () method
3. Through the nodes of
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.