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

Thread: syntax problem

  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    syntax problem

    How do I make a function like this work?

    Code:
    if ("parentElement".hidden=true);
     {
     ("childElement").unactive=true;
     }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Ummm...what does unactive mean?

    And, for that matter, what does "parentElement".hidden mean? That's not even close to valid code.

    Did you mean something like someElement.parentNode.style.visibility == "hidden" perhaps?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, I know its obscenely invalid, its just a placeholder, since I actually have no clue what to put there. Basically, I have this code that expands and collapses divs within an element. That element is a hidden element that shows up when the user clicks a button elsewhere on the page.

    My problem is, there are three of these hidden elements, and I want the expanded elements to collapse when another hidden element is revealed, so that when the user switches between elements, the ones they've clicked on already are not shown.

    The placeholder code uses the pseudo-classes set up in the function, but I don't know what sort of syntax I should be using.

    Code:
    window.onload = function () 
    	{
    	setupDivs( "test", "test2", "test3" );     
    	};
    
    	function setupDivs()
    	{
    	  var bob, args = arguments;
    	  
    	  for( var i = 0; arguments[ i ]; i++ )
    	  {
    		bob = document.getElementById( arguments[ i ] );
    	  
    		if (bob)
    		{
    		  bob.className = 'unactive';
    		  bob.getElementsByTagName( '*' )[0].onclick = f;
    		}
    	  }
    	  
    		//??????????
    		{
    		if ("parentElement".hidden=true);
    			{
    			childNode.unactive=true;
    			}
    		}
    		//????????????
    	  
    	  function f() 
    	  {
    	   this.parentNode.className =  (this.parentNode.className == 'unactive') ? 'active' : 'unactive' ;      
    	  }      
    	}

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Okay, so "unactive" is a class name. Fine.

    But the place you are putting that pseudo-code doesn't make sense to me.

    It's going to be executed *only* when the page first loads.

    Is that really what you want???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well the rest of that code is supposed to load with the page, yes. But I didn't think of the implications of embedding that code. If I make it a separate function, is it possible to make it a self-calling function without limiting it to a startup capacity? How would you recommend doing it otherwise?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    if ("parentElement".hidden=true);

    Spot the syntax errors.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    You can easily do
    Code:
         function foo() { ... do a bunch of stuff ... }
         foo(); // call the function immediately but it's still there for later if needed
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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