For example, create a folder called SpryAssets in the root folder of your web site, and move the SpryAccordion.js file to it. The SpryAccordion.js file contains all of the information necessary for making the Accordion widget interactive.
<script src="SpryAssets/SpryAccordion.js" type="text/javascript"></script>
Make sure that the file path to the SpryAccordion.js file is correct. This path varies depending on where you’ve placed the file in your web site.
<link href="SpryAssets/SpryAccordion.css" rel="stylesheet" type="text/css" />
Make sure that the file path to the SpryAccordion.css file is correct. This path varies depending on where you’ve placed the file in your web site.
<div id="Accordion1" class="Accordion"> </div>
<div id="Accordion1" class="Accordion"> <div class="AccordionPanel"> </div> <div class="AccordionPanel"> </div> </div>
The preceding code adds two panels to the accordion. You can add unlimited panels.
<div class="AccordionPanel"> <div class="AccordionPanelTab">Panel 1 Title</div> </div>
<div class="AccordionPanel"> <div class="AccordionPanelTab">Panel 1 Title</div> <div class="AccordionPanelContent">Panel 1 Content</div> </div>
Insert the content between the opening and closing AccordionPanelContent tags. For example, Panel 1 Content, as in the preceding example. The content can be any valid HTML code, including HTML form elements.
<div id="Accordion1" class="Accordion"> . . . </div> <script type="text/javascript"> var Acc1 = new Spry.Widget.Accordion("Accordion1"); </script>
The new JavaScript operator initializes the Accordion widget object, and transforms the div content with the ID of Accordion1 from static HTML code into an interactive accordion object. The Spry.Widget.Accordion method is a constructor in the Spry framework that creates accordion objects. The information necessary to initialize the object is contained in the SpryAccordion.js JavaScript library that you linked to at the beginning of this procedure.
Make sure that the ID of the accordion’s div tag matches the ID parameter you specified in the Spry.Widgets.Accordion method. Make sure that the JavaScript call comes after the HTML code for the widget.
The complete code looks as follows:
<head> ... <link href="SpryAssets/SpryAccordion.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryAccordion.js" type="text/javascript"></script> </head> <body> <div id="Accordion1" class="Accordion"> <div class="AccordionPanel"> <div class="AccordionPanelTab">Panel 1</div> <div class="AccordionPanelContent"> Panel 1 Content<br/> Panel 1 Content<br/> Panel 1 Content<br/> </div> </div> <div class="AccordionPanel"> <div class="AccordionPanelTab">Panel 2</div> <div class="AccordionPanelContent"> Panel 2 Content<br/> Panel 2 Content<br/> Panel 2 Content<br/> </div> </div> <div class="AccordionPanel"> <div class="AccordionPanelTab">Panel 3</div> <div class="AccordionPanelContent"> Panel 3 Content<br/> Panel 3 Content<br/> Panel 3 Content<br/> </div> </div> <div class="AccordionPanel"> <div class="AccordionPanelTab">Panel 4</div> <div class="AccordionPanelContent"> Panel 4 Content<br/> Panel 4 Content<br/> Panel 4 Content<br/> </div> </div> </div> <script type="text/javascript"> var Acc1 = new Spry.Widget.Accordion("Accordion1"); </script> </body>