Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't I toggle the visibility of every element (within a group) in a for statement, only the last element in the group gets toggled?
    primarykey
    data
    text
    <p>The script fires <code>Toggle</code> fine on each <code>Control</code>'s (<code>Controls[i]</code>) <code>Click</code>. If the <code>Control</code>'s first <code>OL</code> element is not <code>Visible</code> it should be set <code>Visible</code> and all other elements in <code>Controls</code> that are not the current <code>Control</code> (<code>Controls[i]</code>) should be set <code>Hidden</code>. If the <code>Control</code>'s first <code>OL</code> element is <code>Visible</code> it should be set <code>Hidden</code>.</p> <h1>.js</h1> <pre><code>function Toggle(Control){ var Controls=document.getElementsByTagName("ol",document.getElementById("Quote_App")); var Control=Control.getElementsByTagName("ol")[0]; if(Control.style.visibility!="visible"){ for(var i=0;i&lt;Controls.length;i++){ /* (function(){ */ if(Controls[i]!=Control){ Control.style.visibility="hidden"; }else{ Control.style.visibility="visible"; }; /* })(); */ }; }else{ Control.style.visibility="hidden"; }; }; function Event(Mode,Function,Event,Element,Capture_or_Bubble){ if(Mode.toLowerCase()!="remove"){ if(Element.addEventListener){ if(!Capture_or_Bubble){ Capture_or_Bubble=false; }else{ if(Capture_or_Bubble.toLowerCase()!="true"){ Capture_or_Bubble=false; }else{ Capture_or_Bubble=true; }; }; Element.addEventListener(Event,Function,Capture_or_Bubble); }else{ Element.attachEvent("on"+Event,Function); }; }; }; function Controls(){ var Controls=document.getElementById("Quote_App").getElementsByTagName("dd"); for(var i=0;i&lt;Controls.length;i++){ (function(){ var Control=Controls[i]; Event("add",function(){ Toggle(Control); },"click",Control); })(); }; }; Event("add",Controls,"load",window); </code></pre> <p>I am sure it's something with the <code>For</code> statement, in the source you can see I've commented out a closure that I tried, but that too didn't work. I'm still starting out so not very competent with closures.</p> <p>Your help is appreciated, thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload