1. Get in-line (inline) style:
obj.style.attr; Gets a non-inline style.
2. Set the inline style:
Obj.style.attr = value;
3. Get non-inline styles:
function GetStyle (obj,attr) { //get non-inline style, obj is an object, attr is the value if (obj.currentstyle) {/ /get non-inline style return for IE OBJ.CURRENTSTYLE[ATTR]; } else{ return getComputedStyle (Obj,false) [attr]; For non ie };
4. Set the non-inline style:
function css (obj,attr,value) { //object, style, value. To get the style when passing 2 parameters, 3 is to set the style if (arguments.length = = 2) { //arguments parameter array, when the parameter array length is 2 means get CSS style return GetStyle ( OBJ,ATTR); Returns the non-inline style of the object using the GetStyle function above }else{ if (arguments.length = = 3) { //When passing three parameters to set a value for the object obj.style[attr ] = value;};};
JS get/Set inline and non-inline styles