1. Scope of application
The ID can be used except base, head, HTML, script, meta, title tag, and name only applies to select, form, Frame, iframe, IMG, a, input, and so on.
HTML element Input type= ' radio ' grouping, only one radio can be selected at the same time, this grouping is implemented according to the same name property.
2. How to obtain
Get Id:document.getElementById ("id");
Get Name:document.getElementsByName ("name"); note: Because the name value is not unique, the resulting result is a number of groups;
3. Access nodes in the DOM tree using Document.ID and Document.name
Using Document.ID and Document.name to access the nodes in the DOM tree, you can access the IMG element, the IFRAME element, and the form element. However, this approach is not specified in the Web Standard, so support for these methods varies by browser.
Instance:
Use the Document.name property directly to modify the property values of the IMG tag
<HTML><Head><Scripttype= "Text/javascript">functionMouseOver ()
{DOCUMENT.B1.SRC="/i/eg_mouse.jpg"}functionMouseOut () {document.b1.src="/i/eg_mouse2.jpg"}</Script></Head><Body><ahref= "/index.html"Target= "_blank"><imgBorder= "0"alt= "Visit w3school!"src= "/i/eg_mouse2.jpg"name= "B1"onmouseover= "MouseOver ()"
onmouseout= "MouseOut ()" /></a></Body></HTML>
The difference between the name value and the ID value when the JS gets the element