Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery close and open only one element at once
    primarykey
    data
    text
    <p>Before going into my problem, I will post reference where I found partial solution: </p> <ul> <li><a href="https://stackoverflow.com/questions/4656941/jquery-toggle-close-all-except-this/4657463#4657463">Here is the answer to my similar problem</a></li> </ul> <p>Now first I will post my whole example on jsFiddle, stripped down of unnecessary stuff:</p> <ul> <li><a href="http://jsfiddle.net/exwSP/" rel="nofollow noreferrer">My example</a></li> </ul> <p>I will also post the code here:</p> <ul> <li>HTML:</li> </ul> <hr> <pre><code>&lt;ol class="decimalListFirstOl"&gt; &lt;li class="decimalListLi"&gt; Test1 &lt;ol class="decimalListSecondOl"&gt; &lt;li class="columns decimalListLi"&gt; Test1&lt;span class="show"&gt;+&lt;/span&gt; &lt;div class="hide"&gt; &lt;ul class="defaultFont"&gt; &lt;li&gt;Test1&lt;/li&gt; &lt;li&gt;Test2&lt;/li&gt; &lt;li&gt;...&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/li&gt; &lt;li class="columns decimalListLi"&gt; Test2 &lt;span class="show"&gt;+&lt;/span&gt; &lt;div class="hide"&gt; &lt;ul class="defaultFont"&gt; &lt;li&gt;Test1&lt;/li&gt; &lt;li&gt;Test2&lt;/li&gt; &lt;li&gt;...&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/li&gt; &lt;li class="columns decimalListLi"&gt; Test3 &lt;span class="show"&gt;+&lt;/span&gt; &lt;div class="hide"&gt; &lt;ul class="defaultFont"&gt; &lt;li&gt;Test1&lt;/li&gt; &lt;li&gt;Test2&lt;/li&gt; &lt;li&gt;...&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ol&gt; &lt;/li&gt; </code></pre> <p></p> <ul> <li>CSS:</li> </ul> <hr> <pre><code>.hide { display: none; } .columns { float: left; width: 33%; } .decimalListLi { color: #627490; display: block; } .decimalListLi:before { content: counters(item, ".") " "; counter-increment: item; } .decimalListFirstOl { counter-reset: item; font-size: 17px; font-weight: bold; padding-left: 0; } .decimalListSecondOl { counter-reset: item; font-size: 15px; font-weight: normal; padding-left: 25px; } .defaultFont { color: #525252; font-family: Tahoma, Arial, Helvetica, Sans-Serif; font-size: 12px; } </code></pre> <ul> <li>JAVASCRIPT/JQUERY:</li> </ul> <hr> <pre><code>$(document).ready(function() { $('.show').click(function() { var index = $(this).index(); $('.hide').eq(index).slideToggle("slow").siblings('.hide').hide(); }); }); </code></pre> <p>I am using jQuery 1.6.2. I want that one click on the sign(+), closes currently opened column and the clicked column opens (slides down). I have already achieved the opening and closing, but for some reason it always opens and closes the first column, no matter which + is clicked. Now I have followed the answer on first link, but the problem is, I have nested ol and li and that's why probably this line of code:</p> <pre><code>var index = $(this).index(); </code></pre> <p>for some reason always returns 0! Which means it will always open and close the first column.</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.
 

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