Creating HTML objects and elements in JS using createelement

Source: Internet
Author: User

1. Create a link

  

2. Create Div

<script language= "JavaScript" > var o = document.body; Create div function Creatediv (text) {var div = document.createelement ("div"); div.innerhtml = text; O.appendchild (div);} cr Eatediv ("Web Teaching Network: http://www.ffasp.com/");    

  

3. Create a form item

  

4. Create a table
<script language= "JavaScript" > var o = document.body; CREATE TABLE function CreateTable (w,h,r,c) {var table = document.createelement ("table"), var tbody = document.createelement ("t Body "); Table.width = W; Table.height = h; Table.border = 1;    for (Var i=1;i<=r;i++) {var tr = document.createelement ("tr"), for (Var j=1;j<=c;j++) {var td = Document.createeleme NT ("TD"); td.innerhtml = i + "" + j; Td.appendchild (document.createTextNode (i + "" + j)); Td.style.color = "#FF0000"; Tr.appendchild (TD); } tbody.appendchild (TR);    

  

5. Create a Select
jquery words like this
<select id= "Selectid" ></select> $ (function () {   $ ("#selectid"). Click (function () {        $ ("#selectid" ). Append ("<option value= '" +entity+ ">" +entity+ "</option>");//entity variable});   JS words function Padd () {var objoption = document.createelement ("OPTION"); objoption.text= 2;  objoption.value=2;  document.getElementById ("Padd"). Options.add (objoption);} </script>

  

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.