# Expanding Single Panel at a Time When Using Multiple Expansion Panels

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Expansion Panel</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2024.2.514 version</td>
 </tr>
</table>

## Description

How can I allow the user to expand a single panel at a time when using multiple Expansion Panel components? Also, the user must be able to close all panels.

## Solution

1. Handle the `click` event of each Expansion Panel on the page, select the clicked panel, and call the [`toggle()`](https://docs.telerik.com/kendo-ui/api/ui/expansionpanel/methods/toggle) method of the Expansion Panel to toggle the rest of the panels.

   ```Razor HtmlHelper
       @(Html.Kendo().ExpansionPanel()
               .Name("brazil")
               .Title("Brazil")
               .SubTitle("South America")
               .Expanded(true)
               .Content("The word 'Brazil' likely comes from the Portuguese word for brazilwood, a tree that once grew plentifully along the Brazilian coast.")
       )
       @(Html.Kendo().ExpansionPanel()
               .Name("chile")
               .Title("Chile")
               .SubTitle("South America")
               .Content("There are various theories about the origin of the word Chile.")
       )
       @(Html.Kendo().ExpansionPanel()
               .Name("colombia")
               .Title("Colombia")
               .SubTitle("South America")
               .Content("The name 'Colombia' is derived from the last name of the Italian navigator Christopher Columbus.")
       )
   ```

   ```JS scripts
       <script>
           $(document).ready(function() {
               $(".k-expander .k-expander-header").on("click", function() { // Handle the "click" event of each Expansion Panel.
                   let currentPanel = $(this).parent(); // Select the clicked element.
                   let expandedPanels = $(".k-expander").not(currentPanel); // Select the rest of the Expansion Panel elements on the page.
                   $.each(expandedPanels, function(){ // Loop through them.
                       if($(this).hasClass("k-expanded")) { // Check if there are expanded panels.
                           let expandedPanel = $(this).find("[data-role='expansionpanel']").data("kendoExpansionPanel"); //Get a reference to each expanded Expansion Panel.
                           expandedPanel.toggle(); // Toggle it.
                       }
                   });
               });
           });
       </script>
   ```

For a runnable example based on the code above, refer to the [REPL example on expanding a single panel when using multiple Expansion Panel components](https://netcorerepl.telerik.com/cIaVwfPq01IlhFo028).

## More ASP.NET MVC Expansion Panel Resources

* [ASP.NET MVC Expansion Panel Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/layout/expansionpanel/overview)

* [ASP.NET MVC Expansion Panel Demos](https://demos.telerik.com/aspnet-mvc/expansionpanel)

* [ASP.NET MVC Expansion Panel Product Page](https://www.telerik.com/aspnet-mvc/expansionpanel)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Expansion Panel for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/expansionpanel)

* [Server-Side API Reference of the Expansion Panel for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/expansionpanel)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
