Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery show/hide multiple divs
    primarykey
    data
    text
    <p>Please help me in showing/hiding multiple divs in jQuery. I have a PHP code that produce multiple tabs and multiple boxes, with ids that nearly identical. Here is the produced HTML lines:</p> <pre><code>&lt;ul id="tab-country"&gt; &lt;li&gt;&lt;a id="africa" rel="1" href="#"&gt;africa&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="europe" rel="1" href="#"&gt;europe&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="asia" rel="1" href="#"&gt;asia&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="country-glass-1-africa" style="display:none;"&gt;Africa Glass 1&lt;/div&gt; &lt;div id="country-glass-1-europe" style="display:none;"&gt;Europe Glass 1&lt;/div&gt; &lt;div id="country-glass-1-asia" style="display:none;"&gt;Asia Glass 1&lt;/div&gt; &lt;div id="country-spoon-1-africa" style="display:none;"&gt;Africa Spoon 1&lt;/div&gt; &lt;div id="country-spoon-1-europe" style="display:none;"&gt;Europe Spoon 1&lt;/div&gt; &lt;div id="country-spoon-1-asia" style="display:none;"&gt;Asia Spoon 1&lt;/div&gt; &lt;ul id="tab-country"&gt; &lt;li&gt;&lt;a id="africa" rel="2" href="#"&gt;africa&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="europe" rel="2" href="#"&gt;europe&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="asia" rel="2" href="#"&gt;asia&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="country-glass-2-africa" style="display:none;"&gt;Africa Glass 2&lt;/div&gt; &lt;div id="country-glass-2-europe" style="display:none;"&gt;Europe Glass 2&lt;/div&gt; &lt;div id="country-glass-2-asia" style="display:none;"&gt;Asia Glass 2&lt;/div&gt; &lt;div id="country-spoon-2-africa" style="display:none;"&gt;Africa Spoon 2&lt;/div&gt; &lt;div id="country-spoon-2-europe" style="display:none;"&gt;Europe Spoon 2&lt;/div&gt; &lt;div id="country-spoon-2-asia" style="display:none;"&gt;Asia Spoon 2&lt;/div&gt; </code></pre> <p>And at the end of the page, here is the jQuery lines:</p> <pre><code>$(function(){ $("[id$='-africa']").toggle(); $("#tab-country li a").click(function(event){ var country = $(this).attr('id'); var itemid = $(this).attr('rel'); /* the following 2 lines are not working - i want to hide them if they're shown */ $("[id^='country-glass-']"+itemid+"-").css('display','block').toggle(); $("[id^='country-spoon-']"+itemid+"-").css('display','block').toggle(); /* the following works as it is supposed to be */ $("#country-glass-"+itemid+"-"+country).toggle(); $("#country-spoon-"+itemid+"-"+country).toggle(); event.preventDefault(); }); }); </code></pre> <p>Please help me in hiding the shown divs, when one of the tab-country item is clicked. Anyway, thank you for your attention.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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