{"id":12457381,"date":"2020-02-19T20:42:37","date_gmt":"2020-02-19T20:42:37","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/close-dropdown-menu-outside-click\/"},"modified":"2020-02-19T20:42:37","modified_gmt":"2020-02-19T20:42:37","slug":"close-dropdown-menu-outside-click","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/close-dropdown-menu-outside-click\/","title":{"rendered":"Close DropDown Menu Outside Click"},"content":{"rendered":"<p>I have a mobile menu that doesn&#8217;t close on outside clicks. Ironically, the search does close on outside clicks. Here is the code:<\/p>\n<pre><code>mobileMenu: function() {\n\t\t\tvar $closedSymbol = this.cache.$isRTL ? &#039;&#9668;&#039; : &#039;&#9658;&#039;;\n\t\t\tif ( $.fn.slicknav != undefined ) {\n\t\t\t\tvar $mobileMenuAlt = $( &#039;.pwd-mobile-menu-alt ul&#039; );\n\t\t\t\tvar $menu = $mobileMenuAlt.length ? $mobileMenuAlt : $( &#039;.pwd-site-nav-container .pwd-dropdown-menu&#039; );\n\t\t\t\tif ( $menu.length ) {\n\t\t\t\t\t$menu.slicknav( {\n\t\t\t\t\t\tappendTo        : &#039;.pwd-site-header&#039;,\n\t\t\t\t\t\tlabel            : pwdLocalize.mobileSiteMenuLabel,\n\t\t\t\t\t\tallowParentLinks : true,\n\t\t\t\t\t\tclosedSymbol     : $closedSymbol\n\t\t\t\t\t} );<\/code><\/pre>\n<p>This is the code for the Search:<\/p>\n<pre><code>headerSearch: function() {\n\t\t\tvar $headerSearch = $( &#039;.pwd-site-header-search&#039; ),\n\t\t\t\t$headerSearchToggle = $( &#039;.pwd-search-toggle&#039; );\n\t\t\t$headerSearchToggle.click( function() {\n\t\t\t\t$headerSearch.toggleClass( &#039;pwd-active&#039; );\n\t\t\t\treturn false;\n\t\t\t} );\n\t\t\tthis.cache.$document.on( &#039;click&#039;, function( event ) {\n\t\t\t\tif ( ! $( event.target ).closest(  $headerSearch ).length ) {\n\t\t\t\t\t$headerSearch.removeClass( &#039;pwd-active&#039; );\n\t\t\t\t}\n\t\t\t} );<\/code><\/pre>\n<p>What could I add to make this work? Or can I take from the search code and replace with the correct placements? And this is just for the mobile menu. Thanks!<\/p>\n","protected":false},"template":"","class_list":["post-12457381","topic","type-topic","status-publish","hentry","topic-tag-dropdown","topic-tag-menu"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12457381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12457381\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=12457381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}