]|V|[agnus
06-24-2004, 08:52 PM
I was able to find over at CSS-Discuss a thread explaining why this happens: because the property is read from the element's style attribute or whatever is set by JavaScript.
So then this presents a problem with trying to create a generic display toggle switch that I am unsure of how to bypass.
It's easy if all of your elements are going from 'off' to 'on' or vice versa, because then you could have something like this:
function toggleDisplay(elem) { // used for show/hide features
var elem = document.getElementById(elem);
if ((elem.style.display == "none") || (elem.style.display == "")) {
elem.style.display = "block";
} else {
elem.style.display = "none";
}
return false;
}
Or of course, vice versa:
function toggleDisplay(elem) { // used for show/hide features
var elem = document.getElementById(elem);
if ((elem.style.display == "block") || (elem.style.display == "")) {
elem.style.display = "none";
} else {
elem.style.display = "block";
}
return false;
}
But, neither of these will account for a page with elements that default to 'off' AND elements that default to 'on.' In the first scenario, for instance, elements defaulted to 'on' are then turned on again, before being turned 'off' on the second click of the toggle button.
Has anybody dealt with this?
So then this presents a problem with trying to create a generic display toggle switch that I am unsure of how to bypass.
It's easy if all of your elements are going from 'off' to 'on' or vice versa, because then you could have something like this:
function toggleDisplay(elem) { // used for show/hide features
var elem = document.getElementById(elem);
if ((elem.style.display == "none") || (elem.style.display == "")) {
elem.style.display = "block";
} else {
elem.style.display = "none";
}
return false;
}
Or of course, vice versa:
function toggleDisplay(elem) { // used for show/hide features
var elem = document.getElementById(elem);
if ((elem.style.display == "block") || (elem.style.display == "")) {
elem.style.display = "none";
} else {
elem.style.display = "block";
}
return false;
}
But, neither of these will account for a page with elements that default to 'off' AND elements that default to 'on.' In the first scenario, for instance, elements defaulted to 'on' are then turned on again, before being turned 'off' on the second click of the toggle button.
Has anybody dealt with this?