javascript getElementById() method
Translation results:
get
英[get] 美[ɡɛt]
vt.Get; catch; persuade; receive (punishment, etc.)
vt.& vi.arrive, come
vi.become;begin;try to deal with;obtain benefits or wealth
n.Reproduction, cubs; profit
Third person singular: gets Present participle: getting Past tense: got Past participle: got gotten
element
英[ˈelɪmənt] US[ˈɛləmənt]
n.Element; [chemical] element; principle; [electricity] resistance wire
Plural: elements
by
英[baɪ] 美[baɪ]
prep.beside...; means of expression; due to; Pass
adv.pass; indicates reservation or saving; use; short visit
id
##英[ ɪd] n.ID card; genetic quality; instinctive impulse; identifier
javascript getElementById() methodsyntax
Function: Returns a reference to the first object with the specified ID.
Syntax: document.getElementById(id)
Description: HTML DOM defines multiple methods for finding elements, except getElementById (), there are also getElementsByName() and getElementsByTagName(). However, if you need to find a specific element in the document, the most efficient method is getElementById(). When manipulating a specific element of the document, it is best to give the element an id attribute, giving it a unique name (in the document), and then you can use that ID to find the desired element.
javascript getElementById() methodexample
<html> <head> <meta charset="UTF-8"> <script type="text/javascript"> function getValue() { var x=document.getElementById("myHeader") alert(x.innerHTML) } </script> </head> <body> <h1 id="myHeader" onclick="getValue()">这是标题</h1> <p>点击标题,会提示出它的值。</p> </body> </html>
Run instance »
Click the "Run instance" button to view the online instance