View Full Version : style.display probs in NS6
beetle
09-03-2002, 06:16 PM
I've got a simple (should be) function for toggling the display property that is typically called by an onClick event. However, it doesn't work in NS6 (yes, my sniffer variables work ok, they've been tested) After various iterations, here's how the function looks now.function toggleDisp(node) {
if (is_ie4up)
node.style.display = (node.currentStyle.display == 'none') ? 'block' : 'none';
else if (is_gecko)
node.style.display = (node.display != 'block') ? 'block' : 'none';
else
alert('Your browser does not have the javascript support for these menu features.\nPlease upgrade to the most recent version of Internet Explorer, Netscape, or Mozilla.');
}Note: my browser-sniffing variables work fine.
brothercake
09-03-2002, 10:06 PM
Is the initial display property of the element actually "block" ? It might be "inline"
beetle
09-03-2002, 10:34 PM
Well, no. I've tested other values too. Looking at it again, I actually get a JS error - "node.style has no properties"
What are you passing as the node? In Gecko, text nodes can be event targets, while in IE they can't...
beetle
09-03-2002, 10:53 PM
uh oh, methinks the Gecko-empty-text-node-bug* (http://www.codingforums.com/showthread.php?s=&threadid=5247) is gonna bite me in the butt again. Lemme check this out
*bug in this case != error w/Gecko but == a problem to be solved ;)
Why don't you just give an example of this function in action?
What jumps out immediately to me is that you are passing (event.target || event.srcElement) as the argument, which would cause a discrepancy if you actually clicked on the text (as IE is incapable of firing events on text nodes).
event.currentTarget would refer to whatever element you have the onclick attribute on, because the event would have bubbled up to it.
Oh, and it is hardly a bug. It is perfectly valid (and useful at times) behavior to preserve the whitespace as text nodes.
beetle
09-03-2002, 11:04 PM
Yup that was it.
Ok, and jkd, I tried to make the point that I didn't believe it was an acutal programmatic "bug" in Gecko, but rather a bug in my coding that didn't handle it correctly ;)
Oh, and I was passing this.nextSibling
realisis
09-05-2002, 08:54 AM
er, well I just noticed something that hasn't been pointed out:
beetle, in your poriginl post, your sttatement reads:
else if (is_gecko)
node.style.display = (node.display != 'block') ? 'block' : 'none';
*** shouldn't that instead be?***
else if (is_gecko)
node.style.display = (node.style.display != 'block') ? 'block' : 'none';
realisis
09-05-2002, 08:56 AM
"beetle, in your poriginl post, your sttatement reads"
Oops, sorry about the typos. I think my keyboard is drunk again ;^]
That line shouldve been:
"beetle, in your original post, your statement reads"
beetle
09-05-2002, 03:16 PM
realisis
Yes, that's acutally a typo. The true problem was that I needed to remove the empty text nodes for my object associations to reference properly.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.