Creating Accordion Widget

Notes:

jQuery UI - Creating Accordion Widget:
Accordion Widget: is a collapsible and expandable UI control, broken into logical sections

Creating Accordion Widget:

1. Create a new HTML document with basic HTML document structure code

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Accordion Demo</title>
</head>
<body>
</body>
</html>

2. Link the necessary jQueryUI libray files to the HTML document

<link href="jquery-ui/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
<script src="jquery-ui/external/jquery/jquery.js" type="text/javascript"></script>
<script src="jquery-ui/jquery-ui.min.js" type="text/javascript"></script>

3. Code the structure of the widget (i.e. HTML or markup):

To create an accordion widget; we need to create a container with pairs of headers and associated content sections
<div id="accordion">
<h3>Header 1</h3>
<div>Content 1</div>
<h3>Header 2</h3>
<div>Content 2</div>
<h3>Header 3</h3>
<div>Content 3</div>
</div>

4. Select the element using jQuery and call the respective jQuery UI function on it

Select the container div using jQuery selector and call accordion jQuery UI function on it
<script type="text/javascript">
$("#accordion").accordion();
</script>

Interview Questions: