Note that there are some explanatory texts on larger screens.

plurals
  1. POadd a class to each anchor inside an unordered list
    primarykey
    data
    text
    <p>I have a menu and pretty much each item in it has a submenu. the menu system is structured like this</p> <pre><code>&lt;div id="leftNav"&gt; &lt;ul class="level1"&gt; &lt;li&gt;&lt;a href="#"&gt;Link1&lt;/a&gt; &lt;ul class="level2" id="submenu01"&gt; &lt;li class="deptName"&gt;&lt;a href="#"&gt;Link1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link1.1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link1.2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link1.3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link2&lt;/a&gt; &lt;ul class="level2" id="submenu02"&gt; &lt;li class="deptName"&gt;&lt;a href="#"&gt;Link2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link2.1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link2.2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link2.3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>where .level2 is the submenu. I need to add a class to each anchor in the submenu, except for the anchor in the li with the deptName class. this is easy enough, but, i need the class to be "levelTwoLinkXX" where "XX" is the 01 for the first, 02 for the second and so on. Then this needs to happen for each level2 starting back at levelTwoLink01 for the first link not in the deptName class.</p> <p>The javascript I came up with is:</p> <pre><code>$(function(){ $('.level2 &gt; li:not('.deptName') &gt; a').each(function(){ $(this).addClass('levelTwoLink0' + (index+1)); }); }); </code></pre> <p>the problem is that it starts at 01 and by the time it assigns the class to #submenu02 the index is at 4. How would i go about getting it to restart for each new submenuXX?</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.
    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