2metermark
Technical User
Hello all,
I have a chunk of javascript that I use to turn styles on and off on my page, displaying lists of links to other pages on my site. It works great for IE and for FireFox, but does nothing at all in Safari, and Chrome. What am I missing?
Here is the code:
function setStyleClass (classesOff,classesOn) {
var classOn;
if (document.all) {
for (var s = 0; s < document.styleSheets.length; s++)
for (var r = 0; r < document.styleSheets.rules.length; r++){
if (document.styleSheets.rules[r].selectorText.indexOf(classesOff,0) > -1)
document.styleSheets.rules[r].style.display = "none";
for(var j = 0; j < classesOn.length; j++){
classOn = classesOn[j];
if (document.styleSheets.rules[r].selectorText == '.' + classOn)
document.styleSheets.rules[r].style.display = "block";
}
}
}
else if (document.getElementById) {
for (var s = 0; s < document.styleSheets.length; s++)
for (var r = 0; r < document.styleSheets.cssRules.length; r++){
if (document.styleSheets.cssRules[r].selectorText.indexOf(classesOff,0) > -1)
document.styleSheets.cssRules[r].style.display = "none";
for(var j = 0; j < classesOn.length; j++){
classOn = classesOn[j];
if (document.styleSheets.cssRules[r].selectorText == '.' + classOn)
document.styleSheets.cssRules[r].style.display = "block";
}
}
}
}
This gets called by the following when the appropriate link is clicked on:
<a ONCLICK="setStyleClass('B1_Li',['B1_List_41_60','B1_Link_21_40','B1_Link_61_80']);" href="#">Links 41 - 60</a>
The way it works is the first argument (style) is turned off (in this case it's a wild card for every style in "B1", and then the next 3 styles are turned on. It's a great little system - when it works.
Can anyone tell me why this wouldn't work in Safari or Chrome?
Thanks in advance for any comments or suggestions.
Mark
I have a chunk of javascript that I use to turn styles on and off on my page, displaying lists of links to other pages on my site. It works great for IE and for FireFox, but does nothing at all in Safari, and Chrome. What am I missing?
Here is the code:
function setStyleClass (classesOff,classesOn) {
var classOn;
if (document.all) {
for (var s = 0; s < document.styleSheets.length; s++)
for (var r = 0; r < document.styleSheets
if (document.styleSheets
document.styleSheets
for(var j = 0; j < classesOn.length; j++){
classOn = classesOn[j];
if (document.styleSheets
document.styleSheets
}
}
}
else if (document.getElementById) {
for (var s = 0; s < document.styleSheets.length; s++)
for (var r = 0; r < document.styleSheets
if (document.styleSheets
document.styleSheets
for(var j = 0; j < classesOn.length; j++){
classOn = classesOn[j];
if (document.styleSheets
document.styleSheets
}
}
}
}
This gets called by the following when the appropriate link is clicked on:
<a ONCLICK="setStyleClass('B1_Li',['B1_List_41_60','B1_Link_21_40','B1_Link_61_80']);" href="#">Links 41 - 60</a>
The way it works is the first argument (style) is turned off (in this case it's a wild card for every style in "B1", and then the next 3 styles are turned on. It's a great little system - when it works.
Can anyone tell me why this wouldn't work in Safari or Chrome?
Thanks in advance for any comments or suggestions.
Mark