Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no such thing as "jQuery functions", the jQuery code just usually uses an anonymous JavaScript function.</p> <p>To move the contents of the loop into a named function would look like this:</p> <pre><code>$(".x").click( function() { for (var i=0; i&lt;50; i++) toggleItem(i) }); function toggleItem(i) { if ($("#x"+i).is(':hidden')) { $("#x"+i).show(); } else { $("#x"+i).hide(); } } </code></pre> <p>However, you could use the cascading properties of CSS to toggle all the items with a simple JavaScript statement instead of looping through all the elements. Example:</p> <p>CSS:</p> <pre><code>&lt;style type="text/css"&gt; .StateOne .InitiallyHidden { display: none; } .StateTwo .InitiallyVisible { display: none; } &lt;/style&gt; </code></pre> <p>HTML:</p> <pre><code>&lt;div class="StateOne" id="StateContainer"&gt; &lt;div class="InitiallyVisible"&gt;Visible first&lt;/div&gt; &lt;div class="InitiallyHidden"&gt;Visible second&lt;/div&gt; &lt;div class="InitiallyVisible"&gt;Visible first&lt;/div&gt; &lt;div class="InitiallyHidden"&gt;Visible second&lt;/div&gt; &lt;div class="InitiallyVisible"&gt;Visible first&lt;/div&gt; &lt;div class="InitiallyHidden"&gt;Visible second&lt;/div&gt; &lt;div class="InitiallyVisible"&gt;Visible first&lt;/div&gt; &lt;div class="InitiallyHidden"&gt;Visible second&lt;/div&gt; &lt;/div&gt; </code></pre> <p>JavaScript:</p> <pre><code>$('.x').click(function() { var s = document.getElementById('StateContainer'); s.className = (s.className == 'StateOne' ? 'StateTwo' : 'StateOne'); }); </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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