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