Class and ClassName Compatibility methods:
Object.setattribute ("Class", "content")
Can be set successfully in IE8, Chrome, Firefox, Opera10, but cannot be set under IE7.
Object.setattribute ("ClassName", "content")
Only IE7 can be set successfully, but other browsers cannot.
Compatibility method:
Use object.classname= "Content"
Style and Csstext compatibility methods:
Object.setattribute ("Style", "position:absolute;left:10px;top:10px;")
Can be set successfully in IE8, Chrome, Firefox, Opera10, but cannot be set under IE7.
Object.setattribute ("Csstext", "position:absolute;left:10px;top:10px;")
This setting method is not supported by all browsers.
Compatibility method:
Use object.style.csstext= "position:absolute;left:10px;top:10px;"
or separate object.style. Each property is set individually.
Firefox and IE JS compatibility: Set element style familiar
Under IE, the object, collection and event properties of the SetAttribute set element are only used as normal properties, but can be assigned directly, as follows:
var csstext = "font-weight:bold;color:red;"
Use the following for Firefox type browser
Element.setattribute ("style", csstext);
The following wording is used for IE type browser
Element.style.cssText = Csstext;
Issues such as method properties
For example:
var bar = document.getElementById (TESTBT);
Bar.setattribute (onclick, Javascript:alert (' This is a test! '););
Here, we use setattribute to specify the onclick property of E, which is simple and well understood.
But IE does not support, IE does not support setattribute this function, but does not support the use of setattribute set some properties, such as Object properties, collection properties, event properties, In other words, setting style and onclick with setattribute is not feasible in IE.
To achieve compatibility with various browsers, you can use dot notation to set the element's object properties, collection properties, and event properties.
document.getElementById (TESTBT). ClassName = Bordercss;
document.getElementById (TESTBT). Style.csstext = color: #00f;;
document.getElementById (TESTBT). Style.color = #00f;
document.getElementById (TESTBT). onclick= function () {alert (this is a test!);
SetAttribute compatibility