The following function is /SLOW/ - between half a second to a second for just three iterations.
I've already added the stylesheet filtering which has helped a bit, but it's still looping through 53 declarations (rather than just directly changing the relevant one)
Anyone know how to speed it up?
JavaScript code:
function changecss (sheet, theClass, element, value)
{
var result = false;
var cssRules;
if (document.all) cssRules = 'rules';
else if (document.getElementById) cssRules = 'cssRules';
var ss = -(sheet.length+4)
var sl = -4;
for (var S = 0; S < document.styleSheets.length; S++)
{
if (document.styleSheets[S].href.slice(ss,sl) == sheet)
{
var thisRules = document.styleSheets[S][cssRules];
// loops through styles in sheet to find the correct one.
for (var R = 0; R < thisRules.length; R++)
{
if (thisRules[R].selectorText == theClass)
{
thisRules[R].style[element] = value;
result = true;
}
}
if (sheet != '')
{
break;
}
}
}
return result;
}
(I'd like to avoid changing the className of the actual elements, since there's lots of elements compared to just a handful of actual classes used)
EDITED: 12 Mar 2007 15:28 by BOUGHTONP