JavaScript in IE and Firefox browser with differences compatible IE and Firefox (1/6)

Source: Internet
Author: User
Tags reserved

1. CSS Tutorial "float" value
The most basic syntax for accessing a given CSS tutorial value is: Object.style.property, using the hump to replace a value with a connector, for example, to access a <div> Background-color value with the id "header". We use the following syntax:

document.getElementById ("header"). style.backgroundcolor= "#ccc";
But since the word "float" is a JavaScript tutorial reserved word, so we can't use object.style.float to access, here, we can do this in two kinds of browsers:
Write this in IE:

document.getElementById ("header"). Style.stylefloat = "Left";
Write this in Firefox:

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

2. The projection style of the elements
JavaScript tutorials can use Object.style.property syntax to easily access and modify a CSS style externally, but the limitation is that these syntax can only take out the set inline style or the style set directly by JavaScript. Does not have access to an external style sheet. To access the "extrapolated" style of an element, we can use the following code:
Write this in IE:

var myobject = document.getElementById ("header");
var mystyle = Myobject.currentstyle.backgroundcolor;
Write this in Firefox:

var myobject = document.getElementById ("header");
var Mycomputedstyle = Document.defaultview.getcomputedstyle (MyObject, NULL);
var mystyle = Mycomputedstyle.backgroundcolor;
3. Accessing the element's "class"
Like "float", "class" is a reserved word for JavaScript, in which we use the syntax below to access "class".
Write this in IE:

var myobject = document.getElementById ("header");
var myattribute = Myobject.getattribute ("classname");
Write this in Firefox:

var myobject = document.getElementById ("header");
var myattribute = Myobject.getattribute ("class");
This syntax would also apply using the SetAttribute method.

Home 1 2 3 4 5 6 last

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.