Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery Accordion issue due to CMS output
    primarykey
    data
    text
    <p>I am having an issue due to the way my CMS I am using outputs navigational items. I have asked this question before and have received a solution that should work however due to JS not being my strong point I don't get it. A short background. My CMS outputs a menu item like:</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>Wheres the issue? Well the CMS outputs the active selector class in a span, as well as incrementing it depending on the level, currentbranchN as can be seen from the code.</p> <p>I have received help on here on another thread, and we have got to this point:</p> <pre><code>$(document).ready(function () { $('#amenu &gt; li &gt; a').click(function(){ if ($(this).closest("span[class*='currentbranch']").attr('class') != 'active'){ $('#amenu li ul').slideUp(); $(this).next().slideToggle(); $('#amenu li a').closest("span[class*='currentbranch']").removeClass('active'); $(this).closest("span[class*='currentbranch']").addClass('active'); } }); }); </code></pre> <p>But it just doesn't work as an accordion, please see JSFiddle here: <a href="http://jsfiddle.net/EKe2R/5/" rel="nofollow">http://jsfiddle.net/EKe2R/5/</a>. I reckon I am close to getting it working, but as my JS skills are basic at best I cannot seem to get my head around it. I basically need the menu to expand (if a second level item is selected) and highlight the active object, currentbranch1, using the CMS outputted nav items.</p> <p>Thanks! :)</p> <p>Nick </p> <p>Edit: Just to add to this, the main issue the Accordion does not work is that even for second level the CMS outputs for the first level also, causing the code to fail</p> <pre><code>&lt;span class="currentbranch0"&gt;&lt;/span&gt; </code></pre> <p>EDIT:: </p> <p>I am going to try hard coding the thing to slide down, here is the code I have tryed and its failed:</p> <pre><code>$(document).ready(function () { $('#amenu &gt; li &gt; a,#amenu &gt; li &gt; span &gt; a').click(function(){ //alert($(this).closest("span[class='currentbranch0']").attr('class')); if ($(this).closest("span[class='currentbranch0']").attr('class') != 'active'){ $('#amenu li ul').slideUp(); $(this).parents('li').children('ul').slideDown(); $('#amenu li a').closest("span[class='currentbranch0']").removeClass('active'); $(this).closest("span[class='currentbranch0']").addClass('active'); } }); }); </code></pre> <p><a href="http://jsfiddle.net/GgKyV/1/" rel="nofollow">http://jsfiddle.net/GgKyV/1/</a> Fiddle here</p> <p>Also how do I get the fiddle to automatically open the accortion is the link is selected, The first level lis will be actual links to web content, not dummys</p> <p>Cheers</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