Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-03-2002, 05:16 PM   PM User | #1
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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.
Code:
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.
beetle is offline   Reply With Quote
Old 09-03-2002, 09:06 PM   PM User | #2
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Is the initial display property of the element actually "block" ? It might be "inline"
brothercake is offline   Reply With Quote
Old 09-03-2002, 09:34 PM   PM User | #3
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
Well, no. I've tested other values too. Looking at it again, I actually get a JS error - "node.style has no properties"
beetle is offline   Reply With Quote
Old 09-03-2002, 09:47 PM   PM User | #4
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
What are you passing as the node? In Gecko, text nodes can be event targets, while in IE they can't...
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 09-03-2002, 09:53 PM   PM User | #5
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
uh oh, methinks the Gecko-empty-text-node-bug* 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
beetle is offline   Reply With Quote
Old 09-03-2002, 09:58 PM   PM User | #6
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 09-03-2002, 09:58 PM   PM User | #7
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Oh, and it is hardly a bug. It is perfectly valid (and useful at times) behavior to preserve the whitespace as text nodes.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 09-03-2002, 10:04 PM   PM User | #8
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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

Last edited by beetle; 09-03-2002 at 10:07 PM..
beetle is offline   Reply With Quote
Old 09-05-2002, 07:54 AM   PM User | #9
realisis
Regular Coder

 
Join Date: Sep 2002
Location: self.location
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
realisis is an unknown quantity at this point
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 is offline   Reply With Quote
Old 09-05-2002, 07:56 AM   PM User | #10
realisis
Regular Coder

 
Join Date: Sep 2002
Location: self.location
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
realisis is an unknown quantity at this point
"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 is offline   Reply With Quote
Old 09-05-2002, 02:16 PM   PM User | #11
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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.
beetle is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:48 AM.


Advertisement
Log in to turn off these ads.