HuyPV
Sunday, December 19, 2010
function setStyle(objId, style, value){
document.getElementById(objId).style[style]= value;
}
/* USAGE:
* objId = element id.
* style = the style to be changed.
* value = the value assigned to the style.
*/
function getStyle(el, style) {
if(!document.getElementById) return;
var value = el.style[toCamelCase(style)];
if(!value)
if(document.defaultView)
value = document.defaultView.
getComputedStyle(el, "").getPropertyValue(style);
else if(el.currentStyle)
value = el.currentStyle[toCamelCase(style)];
return value;
}
/** toCamelCase(input)
* Converts string input to a camel cased version of itself.
* For example:
* toCamelCase("z-index"); // returns zIndex
* toCamelCase("border-bottom-style"); // returns borderBottomStyle.
*/
function toCamelCase(s) {
for(var exp = toCamelCase.exp;
exp.test(s); s = s.replace(exp, RegExp.$1.toUpperCase()) );
return s;
}
toCamelCase.exp = /-([a-z])/;
Title:
Setting Styles with JavaScript
Description:
function setStyle(objId, style, value){ document.getElementById(objId).style[style]= value; } /* USAGE: * objId = element id. *...
...
Rating:
4