Helpful Information
 
 
Category: DOM and JSON scripting
style.display probs in NS6

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.

Is the initial display property of the element actually "block" ? It might be "inline"

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...

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.

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

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';

"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"

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.










privacy (GDPR)