Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:07:25+00:00 2026-06-05T15:07:25+00:00

Given the jQuery dropdown plugin below. Is there a way to add a method

  • 0

Given the jQuery dropdown plugin below. Is there a way to add a method that would allow for a separate function outside of the dropdown to ‘hideMenu’? Thanks

For example, if I applied the plugin to a div with an ID like so:

$('#settings.dropdown').dropDownMenu();

How could I then call to close the dropDownMenu w hideMenu from outside of the plugin? Thanks

jQuery.fn.dropDownMenu = function() {

    // Apply the Dropdown
    return this.each(function() {

        var dropdown = $(this),
            menu = dropdown.next('div.dropdown-menu'),
            parent = dropdown.parent();

        // For keeping track of what's "open"
        var activeClass = 'dropdown-active',
            showingDropdown = false,
            showingMenu,
            showingParent,
            opening;

        // Dropdown Click to Open
        dropdown.click(function(e) {

            opening = true; // Track opening so that the body click doesn't close. This allows other js views to bind to the click
            e.preventDefault();

            if (showingDropdown) {
                dropdown.removeClass(activeClass);
                parent.removeClass(activeClass);
                showingMenu.hide();
                showingDropdown = false;
            } else {
                showingDropdown = true;
                showingMenu = menu;
                showingParent = parent;
                menu.show();
                dropdown.addClass(activeClass);
                parent.addClass(activeClass);
            }
        });

        // When you click anywhere on the page, we detect if we need to blur the Dropdown Menu
        $('body').click(function(e) {       
            if (!opening && showingParent) {
                var parentElement = showingParent[0];

                if (!$.contains(parentElement, e.target) || !parentElement == e.target) {
                    hideMenu();
                }
            }

            opening = false;

        });

        // hides the current menu
        var hideMenu = function() {
            if(showingDropdown) {
                showingDropdown = false;
                dropdown.removeClass(activeClass);
                parent.removeClass(activeClass);
                showingMenu.hide();
            }
        };

    });

};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:07:27+00:00Added an answer on June 5, 2026 at 3:07 pm

    jQuery advises making multiple methods available through the plugin itself:

    jQuery.fn.dropDownMenu = function(method) {
    
        var methods = {
            init: function() {
                // Put all your init code here
            },
            hide: function() {
                hideMenu();
            }
        };
    
        if ( methods[method] ) {
          return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
          return methods.init.apply( this, arguments );
        } else {
          $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
        }
    
        function hideMenu() {
            // ...
        }
    
    };
    

    See http://docs.jquery.com/Plugins/Authoring#Plugin_Methods

    Update: Use like this:

    // Use the plugin normally to run the init method
    $('#settings.dropdown').dropDownMenu();
    
    // Call the hide method
    $('#settings.dropdown').dropDownMenu('hide');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a jQuery plugin that creates automatically a dropdown year selector (that is
Given the following jquery code.. jQuery.fn.sliding = function () { return this.each(function () {
Given the following javascript (jquery) $(#username).keyup(function () { selected.username = $(#username).val(); var url =
Given the HTML below, I am trying to use jQuery to match all the
I'm looking for a dropdown plugin for jQuery as my app has multiple dropdowns.
I am making use of jQuery's .autocomplete plugin, and I would appreciate some assistance
Does anyone know of a jQuery grid plugin with filterable columns? Obviously there are
I'm using the jQuery bsmSelect plugin to give my users a convenient way to
The following jQuery function filters my table columns by letter. There is an <a>
Given: jQuery.extend({ fooBar: function(){ return 'baz'; } }); does it modify the base jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.