7 JavaScript differences between FF and IE 1th/2 page _javascript tips

Source: Internet
Author: User
In this article, I'll outline 7 aspects of Internet Explorer and Firefox that are different in JavaScript syntax.

1. CSS "Float" property
The basic syntax for obtaining a specific CSS property for a given object is the Object.style property, and the attribute of a hyphen is replaced with a camel naming method. For example, to get the Background-color property of a div with ID "header", we use the following syntax:
document.getElementById ("header"). style.borderbottom= "1px solid #ccc";
But because "float" is a reserved term for JavaScript, we can't use object.style.float to get the "float" attribute. Here are some of the ways we use the two browsers:

IE Syntax:
Copy Code code as follows:

document.getElementById ("header"). Style.stylefloat = "Left";

Firefox Syntax:
Copy Code code as follows:

document.getElementById ("header"). Style.cssfloat = "Left";

2. The calculation style of the elements
By using the above object.style.property,javascript, you can easily get and modify the object's set CSS style. But the limitation of this syntax is that it can only get inline in the HTML style, or directly using JavaScript-style settings. The style object cannot get styles that are set using an external style sheet. To get the "calculation style" of the object, we use the following code:

IE Syntax:
Copy Code code as follows:

var myObject = document.getElementById ("header");
var myStyle = MyObject.currentStyle.backgroundColor;

Firefox Syntax:
Copy Code code as follows:

var myObject = document.getElementById ("header");
var Mycomputedstyle = Document.defaultView.getComputedStyle (myObject, NULL);
var myStyle = Mycomputedstyle.backgroundcolor;

3. Get the element's "class" Property
Similar to the "float" attribute, the two browsers use a different JavaScript method to get this property.

IE Syntax:
Copy Code code as follows:

var myObject = document.getElementById ("header");
var myattribute = Myobject.getattribute ("ClassName");

Firefox Syntax:
Copy Code code as follows:

var myObject = document.getElementById ("header");
var myattribute = Myobject.getattribute ("class");

4. Get Label label "for" property
As with 3, the "for" property that uses JavaScript to get the label also has different syntax.

IE Syntax:
Copy Code code as follows:

var myObject = document.getElementById ("MyLabel");
var myattribute = Myobject.getattribute ("htmlfor");

Firefox Syntax:
Copy Code code as follows:

var myObject = document.getElementById ("MyLabel");
var myattribute = Myobject.getattribute ("for");

The same syntax is true for Setatrribute methods.
Current 1/2 page 12 Next read the full text
Related Article

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.