getElementById () and getElementsByTagName () one is the ID and the other is name what is the difference between them, getElementById () only for HTML operations and not the XML file processing, But getElementsByTagName is OK. Let's take a look at the examples of these two objects tutorial.
getElementById () syntax
document.getElementById ("ID"); I just said it can't manipulate XML documents.
OK, let's take a look at a simple example of the following HTML code.
<div id= ' 111CN ' ></div>
Now I'm going to change the content of ID=111CN's innerhtml. If so, let's take a look at how the DOM is instantiated.
<script>
document.getElementById (' 111CN '). Innerhtml= ' China web first stop ';
</script>
As soon as we run the page will show "China Web first Station"
getElementsByTagName () syntax
document.getElementById (' ID '). getElementsByTagName ("tag name");
It's just one more function of XML manipulation, so let's take a look at a getelementbytagname example.
document.getElementById (' Maindiv '). getElementsByTagName ("P");
To see how to get multiple nodes.
var pp=document.getelementsbytagname ("div");
for (Var i=0;i<pp.length;i++)
{
This will output the node elements below the div.
}
All right, finally, please specify the original site reproduced www.111cn.net