Selectively changing hrefs of a class
<p>I'm working on a drop-down menu, and would like to selectively change the href attribute for certain elements. The menu is made up of two classes, the menuitems and the submenu items. Every menuitem has a corresponding submenu, but some of the submenus contain empty lists. For the menuitems that have an empty submenu list, I want the href to be "#".</p>

<pre><code>&lt;div id="info" class="menuitem"&gt;&lt;a href="http://www.asmithspace.net"&gt;Info&lt;/a&gt;&lt;!--start menuitem--&gt;
&lt;div id="infosubmenu" class="submenu"&gt;&lt;!--start submenu--&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#"&gt;Item1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Item2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Item3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;!--end submenu--&gt;
&lt;/div&gt;&lt;!--end menuitem--&gt;
&lt;div id="business" class="menuitem"&gt;&lt;a href="http://www.asmithspace.net"&gt;Business&lt;/a&gt;&lt;!--start menuitem--&gt;
&lt;div id="businesssubmenu" class="submenu"&gt;&lt;!--start submenu--&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#"&gt;Item1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Item2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;!--end submenu--&gt;
&lt;/div&gt;&lt;!--end menuitem--&gt;
&lt;div id="jobs" class="menuitem"&gt;&lt;a href="http://www.asmithspace.net"&gt;Jobs&lt;/a&gt;&lt;!--start menuitem--&gt;
&lt;div id="jobssubmenu" class="submenu"&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;!--end submenu--&gt;
&lt;/div&gt;&lt;!--end menuitem--&gt;
</code></pre>

<p>I've tried different variations of this code with $.each loops and regular javascript, but everything I've done either changes all the menuitem hrefs to "#", or doesn't change any of them.</p>

<pre><code>if (!$('.menuitem').children('.submenu').children('ul').children('li').length &gt; 0) {
$('.menuitem').children('a').attr('href', '#'); }
</code></pre>

<p>If anyone can show me what I'm doing wrong I'd really appreciate it! My test page can be found <a href="http://www.asmithspace.net/testing/temptest.html" rel="nofollow">here</a>.</p>
