Note that there are some explanatory texts on larger screens.

plurals
  1. POClose the menu when clicked anywhere in body area outside dropdown menu
    text
    copied!<p>I am trying to implement this menu in my web site :</p> <p>Here is the code :</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="jquery-1.4.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery.fixedMenu.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" type="text/css" href="fixedMenu_style1.css" /&gt; &lt;script&gt; $('document').ready(function(){ $('.menu').fixedMenu(); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="menu"&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="#"&gt;More Examples&lt;span class="arrow"&gt;&lt;/span&gt;&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Plugins and jQuery Examples&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Prototype Examples&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Mootools Examples&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Javascript Examples&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Plugins&lt;span class="arrow"&gt;&lt;/span&gt;&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Galleries&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;DropDown Menus&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Content Slider&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;LightBox&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and the code for .js file is :</p> <pre><code>(function($){ $.fn.fixedMenu=function(){ return this.each(function(){ var menu= $(this); menu.find('ul li &gt; a').bind('click',function(){ if ($(this).parent().hasClass('active')){ $(this).parent().removeClass('active'); } else{ $(this).parent().parent().find('.active').removeClass('active'); $(this).parent().addClass('active'); } }) }); } })(jQuery); </code></pre> <p>I want the active menu to be closed when someone clicks anywhere in the body area....</p> <p>I am a newbie to jquery :-) , pls help</p> <p>thanks</p> <p>Sandeep</p> <p>Edit : after your final comments this is how the code looks .</p> <pre><code>$("html").click(function() { menu.find('.active').removeClass('active'); }); (function($){ $.fn.fixedMenu=function(){ return this.each(function(){ var menu= $(this); menu.find('ul li &gt; a').bind('click', function (event) { event.stopPropagation(); }); $("body:not(.menu)").hover(function(){ $(".menu").find('.active').removeClass('active');}) menu.find('ul li &gt; a').bind('click',function(){ if ($(this).parent().hasClass('active')){ $(this).parent().removeClass('active'); } else{ $(this).parent().parent().find('.active').removeClass('active'); $(this).parent().addClass('active'); } }) }); } })(jQuery); </code></pre> <p>but still no success....</p>
 

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