Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #17367

Re: baffled trying to call style.display value

From Jake Jarvis <pig_in_shoes@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: baffled trying to call style.display value
Date 2012-11-27 17:33 +0100
Message-ID <ahk8a9FhjhjU1@mid.uni-berlin.de> (permalink)
References <8b828e29-6604-45c7-9166-f17e5b39724d@googlegroups.com>

Show all headers | View raw


Am 27.11.2012 17:08, schrieb JeffG:
> I am creating a table of contents with nested UL lists. Many of the LI tags contain A tags and the UL of a lower-level list. The A tags call a function meant to show toggle display of the lower level lists.
> The link passes the "this" keyword to the function, which gets the parent node and then finds the sibling UL.
> For some reason, the function is unable to return the style.display value that was set by the CSS file (Loaded before the javascript). So the first time I run the function by clicking the link, my "if" test always goes to the else statement.
> What am I doing wrong?
> Here is the function:
> function TocOpenClose(Anc) {
> 	var parenLI;
> 	var NextUL;
> 	parenLI = Anc.parentNode;
> 	NextUL = parenLI.getElementsByTagName("ul")[0];
>
> 	if (NextUL.style.display=="none")
> 	{
> 		NextUL.style.display = "block";
> 	}
> 	else
> 	{
> 		NextUL.style.display = "none";
> 	}
> }
>

The problem is the style property _only_ reflects inline style 
information (<ul style="...">).

One approach could be to use special class names for the elements, you 
can check for existence and add/remove them relatively easily.

-- 
Jake Jarvis

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

baffled trying to call style.display value JeffG <jeffgutsell@fuse.net> - 2012-11-27 08:08 -0800
  Re: baffled trying to call style.display value Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-27 08:20 -0800
    Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-10 01:24 +0100
      Re: baffled trying to call style.display value Scott Sauyet <scott.sauyet@gmail.com> - 2012-12-10 05:03 -0800
        Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-10 16:04 +0100
          Re: baffled trying to call style.display value Scott Sauyet <scott.sauyet@gmail.com> - 2012-12-10 08:54 -0800
            Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-10 19:36 +0100
          Re: baffled trying to call style.display value Stefan Weiss <krewecherl@gmail.com> - 2012-12-10 22:45 +0100
            Re: baffled trying to call style.display value Andrew Poulos <ap_prog@hotmail.com> - 2012-12-11 10:19 +1100
            Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-11 00:34 +0100
        Re: baffled trying to call style.display value Scott Sauyet <scott.sauyet@gmail.com> - 2012-12-10 07:39 -0800
          Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-10 17:10 +0100
  Re: baffled trying to call style.display value Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-11-27 17:33 +0100
    Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-27 17:49 +0100
  Re: baffled trying to call style.display value JeffG <jeffgutsell@fuse.net> - 2012-11-27 09:38 -0800
    Re: baffled trying to call style.display value Tim Streater <timstreater@greenbee.net> - 2012-11-27 17:59 +0000
      Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-27 21:01 +0100
        Re: baffled trying to call style.display value Tim Streater <timstreater@greenbee.net> - 2012-11-27 22:32 +0000
          Re: baffled trying to call style.display value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-27 23:50 +0100

csiph-web