JS Dom getElementById Instance Tutorial

Source: Internet
Author: User

<title> JS Dom getElementById Instance Tutorial </title>
<body>
<span id= "Span1" >hello,ajax!</span>
</body>
<script language= "JavaScript" type= "Text/javascript" >
<!--
var Span1=document.getelementbyid ("Span1");
Change the contents of a node using the innerHTML property
Span1.innerhtml= "InnerHTML changed";
-->
</script>

The above is a simple example of how the DOM operates on a table

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<title>table test</title>
<body>
<div id= "Tabletest" >
</div>
</body>

<script language= "JavaScript" type= "Text/javascript" >
<!--
Get a reference to a container div
var Container=document.getelementbyid ("Tabletest");
Create a Table object
var _table=document.createelement ("table");
Set Table Properties
_table.setattribute ("Border", "1");
_table.setattribute ("BorderColor", "Black");
_table.setattribute ("width", "200");

Create 5 lines
for (Var i=0;i<5;i++) {
var _tr=document.createelement ("tr");
Create 4 columns
for (Var j=0;j<4;j++) {
var _td=document.createelement ("TD");
var _tn=document.createtextnode (i.ToString () +j.tostring ());
_td.appendchild (_TN);
_tr.appendchild (_TD);
}
_table.appendchild (_TR);
}
Display a table on a page
Container.appendchild (_table);
-->
</script>

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.