so_applyStyleString

Summary

Applies a string of styles to an object.

Arguments:

HTMLElement obj
The element to apply the styles to.
String str
The styles to apply.

Usage:

so_applyStyleString(document.getElementById("mainContainer"),"border:1px solid #000;background-color:#FF0;");

Examples:

No specific examples as this is rather straight forward. Instead of obj.style.background=... and obj.style.border=... you can take care of it all at once.

Code

function so_applyStyleString(obj,str) {
	if(document.all && !window.opera) {
		obj.style.setAttribute("cssText",str);
	} else {
		obj.setAttribute("style",str);
	}
}

License

This code is issued under a Creative Commons license. You do not need my permission to use it, though I'm always interested in seeing where my code has ended up if you want to drop me a line.

slayeroffice main