Return to Snippet

Revision: 33703
at October 12, 2010 11:57 by roblynch


Initial Code
function cssRule(selector,attribute,value,replaceAll)
{
	if(replaceAll == null)
	{
		replaceAll = false;
	}
	
	var ss = document.styleSheets;
	var count = 0;
	for (var i=0; i<ss.length; i++) {
		var rules = ss[i].cssRules || ss[i].rules;

		for (var j=0; j<rules.length; j++) {
			if (rules[j].selectorText === selector) {
				rules[j].style[attribute] = value;
				if(replaceAll)
				{
					count++;
				}
				else
				{
					return true;
				}
			}
		}
	}
	return count;
}

Initial URL

                                

Initial Description
This was useful today, could be made into something with a little work.

Initial Title
Change a CSS rule directly as if you were editing the css file from javascript.

Initial Tags

                                

Initial Language
JavaScript