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.