Createelemen method creates element nodes in IE and FF browser differences

Source: Internet
Author: User

Article Introduction: The similarities and differences of createelement in each browser.

When we create an element node using the Createelemen method, other browsers such as IE and FF will be different.

If we create an INPUT element, under IE, we can have a variety of ways:

<script type= "Text/javascript" >
The first, together with attributes, is created
var x = document.createelement ("<input type= ' text ' size= '/>");
The second type is created in the form of an empty label
var x = document.createelement ("<input/>");
The third type, created in tagname form
var x = document.createelement ("input");

Document.body.appendChild (x);
</script>

All of the above 3 ways in IE can be used, and then no more than IE core browser (such as FF,OP,SF, etc.), the first 2 kinds of writing will be an error, can not correctly create this INPUT element.

Because an element node is created with the CreateElement method in IE, the attributes of that element can be created together, but this is not feasible in other browsers, so we have to create its properties in other ways.

To create a standard notation for an element node with attributes:

<script type= "Text/javascript" >
var x = document.createelement ("input");
X.setattribute ("type", "text");
X.setattribute ("Size", "30");
Document.body.appendChild (x);
</script>

Adding an attribute is Document.setattribute ("attribute", "value") once.

Later found that in fact can also write:

<script type= "Text/javascript" >
var x = document.createelement ("input");
X.type = "text";
Document.body.appendChild (x);
</script>

But using this to create properties, as if not all of the attributes can be created, such as the input of the size,value,class and so in this way can not be created, as for the specific reasons I am not clear. So it is recommended that you use the previous wording.



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.