Title: Dropdown menu
Last modified: February 4, 2020

---

# Dropdown menu

 *  [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/)
 * Hello.
    In the wpadverts plugin on the categories page I wanted to make a drop-
   down menu in javascript, put the classes, but the code didn’t work. Maybe I put
   the classes wrong or the code was written with errors? I found the code on the
   Internet. Can you help me?
 * Classes used such !
 * adverts-categories-all
    adverts-flexbox-wrap adverts-flexbox-list
 *     ```
       document.getElementById('adverts-categories-all').onclick = function(event) {
           var target = event.target;
       	if (target.className == 'adverts-flexbox-wrap') {
       	    var s = target.getElementsByClassName('adverts-flexbox-list');
       		closeMenu();
       		s[0].style.display='block';
             }
       }
       document.onclick=function(event) {
           var target = event.target;
       	console.log(event.target);
       	if (target.className!='adverts-flexbox-wrap' && target.className!='adverts-flexbox-list'){
       	    closeMenu();
       	}
       }
       function closeMenu() {
           var menu = document.getElementById('adverts-categories-all');
       	var subm=document.getElementsByClassName('adverts-flexbox-list');
       	for (var i=0; i <subm.length; i++) {
       	    subm[i].style.display="none";
       	}
       }
       ```
   
 * Thanks you !

Viewing 12 replies - 1 through 12 (of 12 total)

 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12399698)
 * Hi there [@zonepluss](https://wordpress.org/support/users/zonepluss/) I see you
   reported this thread to the moderators. Please note that we are just the folks
   who enforce the rules around all of WordPress.org.
 * Reporting to moderators doesn’t get any faster support, instead it just kind 
   of attracts attention from folks whose radar you probably don’t want to be on.
   😉
 * If you really do need a moderator, please add a reply letting us know why before
   you hit the report button.
 * Otherwise, please hang in there for the plugin’s support to reply when they can.
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12400524)
 * I clicked on the report link by accident, sorry!
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12400623)
 * Hi,
    hmm can you paste a link to a page where you are using this code so i can
   take a look at it on-line?
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12400678)
 * [https://nedia.eu/katalog-obyavleniy/](https://nedia.eu/katalog-obyavleniy/)
   
   Now i’m using CSS to hide subcategories, it works well, but i want to try to 
   display subcategories by clicking, not by hover.
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12404839)
 * With JavaScript and jQuery you should be able to show the sub-items on click 
   by adding the below code in your theme functions.php file
 *     ```
       add_action( "wp_footer", function() {
           ?>
           <script type="text/javascript">
           jQuery(function($) {
               $(".adverts-flexbox-wrap").on("click", function(e) {
                   e.preventDefault();
                   var x = this;
                   $(this).find(".adverts-flexbox-list").toggle();
               });
               $(".adverts-flexbox-list").hide();
           });
           </script>
           <?php
       });
       ```
   
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12405607)
 * Thanks a lot, Greg!
    If i want to add some link or simple text like “show all”
   to the flexbox, below the main category, that users can click on this text and
   then subcategories dropdown, i need create this with js or theme html before?
   Regards
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12408920)
 * I would recommend creating it with JavaScript since there is already a part of
   the code available above, plus the changes in the templates could be overwritten
   on WPAdverts update.
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12409057)
 * Sorry,but could you help us?
 * It’s currently not possible to select a category and subcategory, that is, they
   are not active.
    With this code, we can only open and close a category.
 * Thanks you !
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12416494)
 * Please try replacing the code from previous message with the one below
 *     ```
       add_action( "wp_footer", function() {
           ?>
           <script type="text/javascript">
           jQuery(function($) {
               $(".adverts-flexbox-wrap").on("click", function(e) {
                   e.preventDefault();
                   var x = this;
                   $(this).find(".adverts-flexbox-list").toggle();
               });
               $(".adverts-flexbox-list a").on("click", function(e) {
                   $(".adverts-flexbox-wrap").unbind("click");
               });
               $(".adverts-flexbox-list").hide();
           });
           </script>
           <?php
       });
       ```
   
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12416862)
 * Thank You so much Greg, work perfectly!!!
    Last question, how can i add small
   buttons or text like SHOW and HIDE, that user could press SHOW button to see 
   subcategories and then press HIDE to close subcategories. Regards!
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12420840)
 * This would require even more custom programming, this is beyond the support offered
   here, sorry.
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12420897)
 * Ok, thanks, Greg!

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Dropdown menu’ is closed to new replies.

 * ![](https://ps.w.org/wpadverts/assets/icon-256x256.png?rev=2423472)
 * [WPAdverts - Classifieds Plugin](https://wordpress.org/plugins/wpadverts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpadverts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpadverts/)
 * [Active Topics](https://wordpress.org/support/plugin/wpadverts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpadverts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpadverts/reviews/)

 * 12 replies
 * 3 participants
 * Last reply from: [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/dropdown-menu-71/#post-12420897)
 * Status: not resolved