Note that there are some explanatory texts on larger screens.

plurals
  1. POIdentify active class from span in accordion
    text
    copied!<p>Ok folks,</p> <p>I am having some issues with producing an accordion menu with Jquery for a CMS I must use. This old CMS assigns the "active" item class in a span tag, and not the a or li ones. I need to be able to set the active tab via the code activating the span tag, and not the li anchor tag like I have already. Heres the example:</p> <pre><code> &lt;script type="text/javascript"&gt; $(document).ready(function () { $('#amenu &gt; li &gt; a').click(function(){ if ($(this).attr('class') != 'active'){ $('#amenu li ul').slideUp(); $(this).next().slideToggle(); $('#amenu li a').removeClass('active'); $(this).addClass('active'); } }); }); &lt;/script&gt; </code></pre> <p>Example output from the CMS is below:</p> <pre><code>&lt;ul id="amenu"&gt; &lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="currentbranch0"&gt; &lt;a href=""&gt;Content&lt;/a&gt;&lt;/span&gt; &lt;ul class="multilevel-linkul-0" title=""&gt; &lt;li&gt;&lt;a href=""&gt;Content 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;span class="currentbranch1"&gt;&lt;a href=""&gt;Content 3&lt;/a&gt;&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>How would I approach tackling this problem would anyone know? I have different combinations but keep breaking the anchor link. Also if I set the anchor active class manually on the page the accordion won't expand the children, as I will be using a CMS though this might not be that big a deal.</p> <p>Any help would be appreciated</p> <p>Regards</p> <p>Nick</p>
 

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