Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is the initial display property of the element actually "block" ? It might be "inline"

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, no. I've tested other values too. Looking at it again, I actually get a JS error - "node.style has no properties"

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    What are you passing as the node? In Gecko, text nodes can be event targets, while in IE they can't...

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #7
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Oh, and it is hardly a bug. It is perfectly valid (and useful at times) behavior to preserve the whitespace as text nodes.

  • #8
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Regular Coder
    Join Date
    Sep 2002
    Location
    self.location
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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';

  • #10
    Regular Coder
    Join Date
    Sep 2002
    Location
    self.location
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "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"

  • #11
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •