I have been working on a horizontal menu that is functioning well for me. However, according to the design requirements, I need to adjust the height of
<div id="nav-subMenu"></div>
if the main/parent menu li
does not have any submenus or ul
. The jQuery code that I have written for this purpose is not working as expected. Any assistance in resolving this issue would be greatly appreciated.
For reference, here is an example on jsFiddle
if ($('#nav-wrapper ul li').has('ul'))
always returns true
.
Sample jQuery Code:
jQuery(document).ready(function () {
if ($('#nav-wrapper ul li').hasClass('active')) { //if it has the "active" class
if ($('#nav-wrapper ul li').has('ul')) {
alert('aaaa');
$('#nav-subMenu').css("height", "30");
}
}
});
Sample HTML Code:
<div id="nav-wrapper">
<ul class="dropdown dropdown-linear" id="nav">
<li><span class="dir"><a href="#">Home</a></span></li>
<li><span class="dir"><a href="#">About Us</a></span></li>
<li><span class="dir"><a href="Articles.aspx?PageID=5&Language=en-us&ParID=0&Issue=5&CID=1">Articles</a></span></li>
<li class="active">
<span class="dir"><a href="Page.aspx?PageID=6&Language=en-us&ParID=0&Issue=5&CID=1">Categories</a></span>
<ul>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=18">Book Review</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=16">Business</a></li>
(Other list items omitted for brevity)
</ul>
</li>
(Other list items omitted for brevity)
</ul>
</div>
<div id="nav-subMenu"></div>
<div id="NewsTicker"> </div>
UPDATE: Firebug gives a view to help understand when the jQuery should trigger to adjust the height of the DIV.