Getting started in EJ2 JavaScript Accordion

24 Nov 20266 minutes to read

The Essential® JS 2 for JavaScript (global script) is an ES5 formatted pure JavaScript framework which can be directly used in latest web browsers.

Create a Folder and HTML File

  • Create a folder named quickstart in your desired directory.

  • Inside the quickstart folder, create a new file named index.html.

Control Initialization

The Essential® JS 2 JavaScript controls can be initialized by using below css styles and scripts

Add Syncfusion® Accordion CSS Styles and Scripts

Include the following CSS and JavaScript files from CDN in the <head> section of the index.html file. The ej2-base script is the required dependency package for the Accordion component.

Styles(CSS):

https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/accordion/index.css

Scripts (javascript):

https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/dist/global/ej2-base.min.js
https://cdn.syncfusion.com/ej2/35.1.37/ej2-navigations/dist/global/ej2-navigations.min.js

Initialize the Accordion using HTML elements

The Accordion component can be rendered based on the given HTML element using id as target property.
You need to follow the below structure of HTML elements to render the Accordion.

  <div id='accordion_html_markup'>   --> Root Accordion Element
       <div>      --> Accordion Item Container
            <div>   --> Accordion Header Container
                <div> </div> --> Accordion Header
            </div>
            <div>  --> Accordion Panel Container
                <div> </div> --> Accordion Content
             </div>
        </div>
  </div>
ej.base.enableRipple(true);

//Initialize Accordion component

    var accordion = new ej.navigations.Accordion({});

//Render initialized Accordion component
    accordion.appendTo('#accordion_html_markup');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 Accordion</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Toolbar Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/accordion/index.css" rel="stylesheet" />
    
    
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="accordion_html_markup">
            <div>
                <div>
                    <div> ASP.NET </div>
                </div>
                <div>
                    <div> Microsoft ASP.NET is a set of technologies in the Microsoft .NET Framework for building Web applications
                        and XML Web services </div>
                </div>
            </div>
            <div>
                <div>
                    <div> ASP.NET MVC </div>
                </div>
                <div>
                    <div> The Model-View-Controller (MVC) architectural pattern separates an application into three main components:
                        the model, the view, and the controller </div>
                </div>
            </div>
            <div>
                <div>
                    <div> JavaScript </div>
                </div>
                <div>
                    <div> JavaScript (JS) is an interpreted computer programming language.It was originally implemented as part
                        of web browsers so that client-side scripts could interact with the user, control the browser </div>
                </div>
            </div>
        </div>
        <br><br>
        <div id="result"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

You can add the custom class into Accordion component using cssClass property which is used to customize the Accordion component.

See Also