Dom Tutorials: getElementById () and getElementsByTagName ()

Source: Internet
Author: User
Tags tag name

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

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.