i write a function want to set or get style property value:
function $(ID){return document.getElementById(ID);}
Object.prototype.css=function(style,value){
if(value==undefined){
return eval("this.style."+style);
}
else{
if(isNaN(value)){
return eval("this.style."+style+"=\""+value+"\"");
}
else{
return eval("this.style."+style+"="+value);
}
}
}
function ad(){
$("ad_ol").css("top","-170px");
}
it can work well in FireFox 、 Chrome and IE9,but not work in IE7 and IE8,error message is:Object does not support the “css” property or method
who can help me? is the “this” problem? is have better function can do this?
No need for eval, and there are other flaws in you code.
Try using something like: