Creating HTML objects and elements in JS using createelement

Source: Internet
Author: User

1. Create a link

<script language="JavaScript">varo =document.body;//Create a linkfunction Createa (url,text) {varA = Document.createelement ("a"); A.href=URL; a.innerhtml=text; A.style.color="Red"; O.appendchild (a);} Createa ("http://www.ffasp.com/","Web Teaching Network"); </script>

2. Create Div

<script language="javascript"var o =//   var div = document.createelement ("div"= text; O.appendchild (DIV); } creatediv (" Web Teaching Network: http://www.ffasp.com/");    

3. Create a form item

<script language="JavaScript">varo =document.body;//Create a form itemfunction Createinput (stype,svalue) {varinput = Document.createelement ("input"); Input.type=stype; Input.value=svalue; o.appendchild (input);} Createinput ("Button","ooo"); </script>

4. Create a table

<script language="JavaScript">varn \document.body;//Create a tablefunction CreateTable (w,h,r,c) {varTable = Document.createelement ("Table"); varTbody = Document.createelement ("tbody"); Table.width=W; Table.height=h; Table.border=1;  for(varI=1; i<=r;i++) { varTR = document.createelement ("TR");  for(varj=1; j<=c;j++) { varTD = Document.createelement ("TD"); Td.innerhtml= i +""+J;//Td.appendchild (document.createTextNode (i + "" + j));Td.style.color ="#FF0000"; Tr.appendchild (TD);}    Tbody.appendchild (TR); } table.appendchild (TBODY); O.appendchild (table); } createtable ( the, the,9,9); </script>

Reprinted from: http://wangyj0898.blog.51cto.com/1519857/343660/

Creating HTML objects and elements in JS using createelement

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.