I am working on a Horizontal menu which works fine for me but as per design requirement i need to change the height of <div id="nav-subMenu"></div>
if main/parent menu li
doesn't have any ul
or submenus in other words. jquery which i wrote is not working for me i would appreciate help in this regard.
Here is an example of jsFiddle
if ($('#nav-wrapper ul li').has('ul'))
always return true
Sample jQuery
jQuery(document).ready(function () {
if ($('#nav-wrapper ul li').hasClass('active')) { //if it does have the class active
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>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=3">Culture</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=2">Economy</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=19">Finance</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=17">Infrastructure</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=20">Lifestyle</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=21">Others</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=7">People</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=1">Politics</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=4">Sports</a></li>
</ul>
</li>
<li><span class="dir"><a href="News.aspx?PageID=3&Language=en-us&ParID=0&Issue=5&CID=1">News</a></span></li>
<li>
<span class="dir"><a href="Page.aspx?PageID=12&Language=en-us&ParID=0&Issue=5&CID=1">Archive</a></span>
<ul>
<li><a href="Page.aspx?PageID=1&Language=1&ParID=12&Issue=1&CID=1">106</a></li>
<li><a href="Page.aspx?PageID=3&Language=1&ParID=12&Issue=3&CID=1">102</a></li>
<li><a href="Page.aspx?PageID=4&Language=1&ParID=12&Issue=4&CID=1">103</a></li>
<li><a href="Page.aspx?PageID=5&Language=1&ParID=12&Issue=5&CID=1">109</a></li>
</ul>
</li>
<li>
<span class="dir"><a href="Multimedia.aspx?PageID=10&Language=en-us&ParID=0&Issue=5&CID=1">Multimedia</a></span>
<ul>
<li><a href="Videos.aspx?PageID=11&Language=1&ParID=10&Issue=1&CID=1">Video</a></li>
</ul>
</li>
</ul>
</div>
<div id="nav-subMenu"></div>
<div id="NewsTicker"> </div>
UPDATE: Firebug view to get idea when jquery should fire to add height to DIV
I found your problem and this is working as you desired, try this out:
jQuery(document).ready(function () {
if ($("#nav-wrapper li.active").length) {
alert('yes there are .active class');
if ($(".active").has('ul').length) {
alert('yes .active class has ul');
$('#nav-subMenu').css("height", "60px");
} else {
alert("NO .active class don't have ul");
$('#nav-subMenu').css("height", "0px");
}
} else {
alert("NO .active class found.");
}
});
check this out in the fiddle here: http://jsfiddle.net/zMty8/27/
Try this:
if ($('#nav-wrapper ul li').has('ul')) {
$('#nav-subMenu').css("height", "30px");
}
if ($('#nav-wrapper ul li').has('ul')) {
alert('a');
$('#nav-subMenu').css("height", "30px");
}
Reference here
Check this code:
jQuery(document).ready(function () {
if ($('#nav-wrapper ul li').hasClass('active')) { //if it doesn't have the class active
if ($('#nav-wrapper ul li > ul'.length > 0)) {
$('#nav-subMenu').css("height", "30");
}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.