Skip to content
Related Articles
Open in App
Not now

Related Articles

jQuery UI menu collapse() Method

Improve Article
Save Article
  • Last Updated : 24 Jan, 2021
Improve Article
Save Article

jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. jQuery UI menu is a themeable menu that is used with mouse and keyboard interactions for navigating between pages. In this article, we will use the collapse option to collapse the active sub-menu. 


$(".selector").menu( "collapse" );


  • First, add jQuery UI scripts needed for your project.

<link href = “” rel = “stylesheet”>

<script src = “”></script>

<script src = “”></script>

Example 1: In this example, we will be using the collapse option for the menu() method. 


<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <link href=
    <script src=""></script>
        .ui-menu {
            width: 200px;
        $(function() {
            var menu = $("#gfg").menu();
            $(menu).mouseleave(function() {
    <h1>jQuery UI | menu collapse method</h1>
    <ul id="gfg">
        <li><a href="#">Menu</a>
                <li><a href="#">Submenu</a>
                        <li><a href="#">


  • With collapse method.

  • Without collapse method. In the following image, please notice that the sub-sub menu is not getting collapsed as in the first image.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!