Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect element using an id with increasing number jquery
    text
    copied!<p>I created a multiple toggle for a number of links in the same page. They are all closed (with a plus sign) and on click each of them will open a div (and will show a minus sign). </p> <p>I could get the toggle to work but I'm stuck with the plus and minus signs. When one link is open all the links will show the minus sign.</p> <p>Each <code>a</code> has an id with a number from <code>1</code> to <code>15</code>. </p> <p>How do we get only the one opened to show the minus sign and all the others the plus sign?</p> <p>Please advice</p> <p><strong>Here the code used:</strong></p> <pre><code>$('.questions a').removeClass('DownArrow'); $('.questions a').addClass('RightArrow'); function toggleDiv(divId) { $("#"+divId).toggle(); $('.questions a').toggleClass('DownArrow'); $('.questions a').toggleClass('RightArrow'); } </code></pre> <p><strong>HTML:</strong></p> <pre><code>&lt;div class='questions'&gt; &lt;a class="DownArrow" id="numb-1" href="javascript:toggleDiv('myContent1');"&gt;text&lt;/a&gt; &lt;/div&gt; &lt;div id="myContent1"&gt; &lt;p&gt;some text&lt;/p&gt; &lt;/div&gt; &lt;div class='questions'&gt; &lt;a class="DownArrow" id="numb-2" href="javascript:toggleDiv('myContent2');"&gt;text&lt;/a&gt; &lt;/div&gt; &lt;div id="myContent2"&gt; &lt;p&gt;some text&lt;/p&gt; &lt;/div&gt; </code></pre> <p><strong>Here the CSS:</strong></p> <pre><code>div#questions a { display:block; border:1px solid #F00; width:500px; padding:10px; } div#myContent1,div#myContent2,div#myContent3,div#myContent4,div#myContent5 { display:none; } a.DownArrow { background:#ccc url(../images/plus.png) no-repeat 460px 8px; } a.RightArrow { background:#ccc url(../images/minus.png) no-repeat 460px 8px; } </code></pre>
 

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