{"id":290,"date":"2020-11-27T02:30:00","date_gmt":"2020-11-27T02:30:00","guid":{"rendered":"https:\/\/wshop.fi\/eng\/?p=290"},"modified":"2021-03-23T02:39:02","modified_gmt":"2021-03-23T02:39:02","slug":"basic-jquery-ui-accordion-tutorial","status":"publish","type":"post","link":"https:\/\/wshop.fi\/eng\/basic-jquery-ui-accordion-tutorial\/","title":{"rendered":"jQuery UI Accordion Tutorial: How to Make a Basic jQuery UI Accordion"},"content":{"rendered":"\n<p>This post is for beginners. \u00a0It shows\u00a0<strong>how to make a basic jquery UI accordion.<\/strong>\u00a0We will use a predefined\u00a0jquery ui for the accordion. There is a link to the demo right before the entire code snippet.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault-1024x576.jpg\" alt=\"Image of jQuery UI Accordion\" class=\"wp-image-291\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault-1024x576.jpg 1024w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault-300x169.jpg 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault-768x432.jpg 768w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault-696x392.jpg 696w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault-1068x601.jpg 1068w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault-747x420.jpg 747w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/maxresdefault.jpg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">HTML for Basic jQuery UI Accordion<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;!-- begin html for accordion -->\n    &lt;div style=\"width: 360px;\">\n        &lt;div id=\"accordion\">\n            &lt;h3>\n                &lt;a href=\"#\">ASP.NET&lt;\/a>&lt;\/h3>\n            &lt;div class=\"\">\n                &lt;h4>\n                    ASP&lt;\/h4>\n                &lt;p>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/tag\/asp\/\">ASP stuff&lt;\/a>&lt;\/p>\n            &lt;\/div>\n            &lt;h3>\n                &lt;a href=\"#\">CSS&lt;\/a>&lt;\/h3>\n            &lt;div>\n                &lt;h4>\n                    CSS&lt;\/h4>\n                &lt;p>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/tag\/css\/\">CSS Stuff&lt;\/a>&lt;br \/>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/css\/clearfix.html\">CSS Clearfix&lt;\/a>\n                &lt;\/p>\n            &lt;\/div>\n            &lt;h3>\n                &lt;a href=\"#\">Javascript&lt;\/a>&lt;\/h3>\n            &lt;div>\n                &lt;h4>\n                    Javascript&lt;\/h4>\n                &lt;p>\n                    javascript&lt;br \/>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/tag\/jquery\/\">jQuery&lt;\/a>&lt;br \/>\n                    Dojo&lt;br \/>\n                    Backbone&lt;\/p>\n            &lt;\/div>\n        &lt;\/div>\n    &lt;\/div><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">HTML Code in header<\/h2>\n\n\n\n<p>The first 2 reference the jQuery library and the jQuery UI library to make the accordion functional. \u00a0The third gets the CSS needed from a theme for the look.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script type=\"text\/javascript\" src=\"http:\/\/code.jquery.com\/jquery-1.9.1.js\">&lt;\/script>\n&lt;script type=\"text\/javascript\" src=\"http:\/\/code.jquery.com\/ui\/1.10.2\/jquery-ui.js\">&lt;\/script>\n&lt;link rel=\"stylesheet\" type=\"text\/css\" href=\"http:\/\/code.jquery.com\/ui\/1.10.2\/themes\/dark-hive\/jquery-ui.css\" \/><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">jQuery for Accordion<\/h2>\n\n\n\n<p>Here is the jQuery code to make the accordion work. &nbsp;Several parameters are included. &nbsp;Hopefully this will help you tweak as needed&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.surfingsuccess.com\/wp-includes\/images\/smilies\/icon_smile.gif\" alt=\":)\"\/><\/figure>\n\n\n\n<p>&nbsp;&nbsp;If you need info on more parameters, I would start&nbsp;<a href=\"http:\/\/www.jquerysdk.com\/api\/accordion\" target=\"_blank\" rel=\"noreferrer noopener\">here&nbsp;first<\/a>, then&nbsp;<a href=\"http:\/\/api.jqueryui.com\/accordion\/\">here<\/a>, then&nbsp;<a href=\"http:\/\/docs.jquery.com\/UI\/API\/1.8\/Accordion\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     $(document).ready(\n            function () {\n                $(\"#accordion\").accordion({ header: \"h3\",          \n                    autoheight: false,\n                    active: false,\n                    alwaysOpen: false,\n                    fillspace: false,\n                    collapsible: true,\n            \/\/heightStyle: 'content'   \/\/auto, fill, content\n                });\n            });<\/code><\/pre>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"http:\/\/www.surfingsuccess.com\/demos\/accordion\/accordion\/\" target=\"_blank\"><strong>View Demo<\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Entire jQuery UI Accordion Code<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n&lt;head>\n    &lt;title>Basic jQuery Accordion&lt;\/title>\n    &lt;script type=\"text\/javascript\" src=\"http:\/\/code.jquery.com\/jquery-1.9.1.js\">&lt;\/script>\n    &lt;script type=\"text\/javascript\" src=\"http:\/\/code.jquery.com\/ui\/1.10.2\/jquery-ui.js\">&lt;\/script>\n    &lt;link rel=\"stylesheet\" type=\"text\/css\" href=\"http:\/\/code.jquery.com\/ui\/1.10.2\/themes\/dark-hive\/jquery-ui.css\" \/>\n    &lt;script type=\"text\/javascript\">\n          $(document).ready(\n            function () {\n                $(\"#accordion\").accordion({ header: \"h3\",          \n                    autoheight: false,\n                    active: false,\n                    alwaysOpen: false,\n                    fillspace: false,\n                    collapsible: true,\n                    \/\/heightStyle: content   \/\/auto, fill, content\n                });\n            });\n    &lt;\/script>\n&lt;\/head>\n&lt;body>\n    &lt;script type=\"text\/javascript\" src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n    &lt;\/script>\n    &lt;!-- begin html for accordion -->\n    &lt;div style=\"width: 468px;\">\n        &lt;div id=\"accordion\">\n            &lt;h3>\n                &lt;a href=\"#\">ASP.NET&lt;\/a>&lt;\/h3>\n            &lt;div class=\"\">\n                &lt;h4>\n                    ASP&lt;\/h4>\n                &lt;p>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/tag\/asp\/\">ASP stuff&lt;\/a>&lt;\/p>\n            &lt;\/div>\n            &lt;h3>\n                &lt;a href=\"#\">CSS&lt;\/a>&lt;\/h3>\n            &lt;div>\n                &lt;h4>\n                    CSS&lt;\/h4>\n                &lt;p>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/tag\/css\/\">CSS Stuff&lt;\/a>&lt;br \/>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/css\/clearfix.html\">CSS Clearfix&lt;\/a>\n                &lt;\/p>\n            &lt;\/div>\n            &lt;h3>\n                &lt;a href=\"#\">Javascript&lt;\/a>&lt;\/h3>\n            &lt;div>\n                &lt;h4>\n                    Javascript&lt;\/h4>\n                &lt;p>\n                    javascript&lt;br \/>\n                    &lt;a href=\"http:\/\/www.surfingsuccess.com\/tag\/jquery\/\">jQuery&lt;\/a>&lt;br \/>\n                    Dojo&lt;br \/>\n                    Backbone&lt;\/p>\n            &lt;\/div>\n            &lt;h3>\n                &lt;a href=\"#\">Other&lt;\/a>&lt;\/h3>\n            &lt;div>\n                &lt;h4>\n                    Stuff&lt;\/h4>\n                &lt;p>\n                &lt;\/p>\n            &lt;\/div>\n        &lt;\/div>\n    &lt;\/div>\n    &lt;!--&lt;\/div>-->\n    &lt;!-- end html for accordion -->\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This post is for beginners. \u00a0It shows\u00a0how to make a basic jquery UI accordion.\u00a0We will use a predefined\u00a0jquery ui for the accordion. There is a link to the demo right before the entire code snippet. HTML for Basic jQuery UI Accordion HTML Code in header The first 2 reference the jQuery library and the jQuery [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":286,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":{"0":"post-290","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-coding"},"_links":{"self":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/comments?post=290"}],"version-history":[{"count":2,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/290\/revisions"}],"predecessor-version":[{"id":293,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/290\/revisions\/293"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media\/286"}],"wp:attachment":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media?parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/categories?post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/tags?post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}