{"id":496,"date":"2013-06-11T01:13:17","date_gmt":"2013-06-11T01:13:17","guid":{"rendered":"http:\/\/tregner.com\/flare-blog\/?p=496"},"modified":"2013-06-11T01:13:17","modified_gmt":"2013-06-11T01:13:17","slug":"show-and-hide-with-jquery-in-html5-output","status":"publish","type":"post","link":"https:\/\/tregner.com\/flare-blog\/show-and-hide-with-jquery-in-html5-output\/","title":{"rendered":"Show and Hide with jQuery in HTML5 Output"},"content":{"rendered":"<p>MadCap Flare includes some show-and-hide controls for web-based outputs such as\u00a0<a href=\"http:\/\/webhelp.madcapsoftware.com\/flare9\/Default.htm#Nav_Links\/Togglers\/Inserting_Togglers_into_Topics.htm\" target=\"_blank\">Togglers<\/a>\u00a0and <a href=\"http:\/\/webhelp.madcapsoftware.com\/flare9\/Default.htm#Nav_Links\/Expanding_Text\/Inserting_Expanding_Text_into_Topics.htm\" target=\"_blank\">Expanding Text<\/a>. This blog has explored some alternatives for show-and-hide in the context of condition tags. Here is another option which uses jQuery to expand and collapse an element with a sliding animation.<\/p>\n<p>Sliding show-and-hide actions are simple tasks with jQuery. Two such functions are\u00a0<a href=\"http:\/\/api.jquery.com\/slideUp\/\" target=\"_blank\">slideUp()<\/a>\u00a0and\u00a0<a href=\"http:\/\/api.jquery.com\/slideDown\/\" target=\"_blank\">slideDown()<\/a>. Here is a function which uses both functions to show and hide an element given the element&#8217;s id attribute value.<\/p>\n<pre class=\"lang:js decode:true\" title=\"jQuery slideDown and slideUp for expand\/collapse\">function slideContent(id) {\r\n    if ($('#' + id).css('display') == 'none') {\r\n        $('#' + id).slideDown('slow', function () { });\r\n    }\r\n    else {\r\n        $('#' + id).slideUp('slow', function () { });\r\n    }\r\n}<\/pre>\n<p>You can add this script to many places in a Flare project. For simplicity in this example, here is an image of the script inserted into a topic and then edited.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/insert-script.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-498\" alt=\"insert-script\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/insert-script.png\" width=\"714\" height=\"344\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/insert-script.png 714w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/insert-script-300x144.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/insert-script-624x300.png 624w\" sizes=\"(max-width: 714px) 100vw, 714px\" \/><\/a><\/p>\n<p>With the <a href=\"http:\/\/webhelp.madcapsoftware.com\/flare9\/Default.htm#UI_Elements\/Attributes_Window.htm\" target=\"_blank\">Attributes Window in Flare<\/a>, you can set the value for an attribute of an element highlighted in the XML Editor. You can also edit the markup directly with the Text Editor. For this example the element to show and hide is given the value &#8216;show-hide&#8217; for the id attribute.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/id-attribute.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-499\" alt=\"id-attribute\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/id-attribute.png\" width=\"619\" height=\"276\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/id-attribute.png 619w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/id-attribute-300x133.png 300w\" sizes=\"(max-width: 619px) 100vw, 619px\" \/><\/a><\/p>\n<p>The element to click is given the following value for the onclick attribute to call the JavaScript function. The value for id is passed to the function:<\/p>\n<pre>slideContent('show-hide')<\/pre>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/onclick-attribute.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-500\" alt=\"onclick-attribute\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/onclick-attribute.png\" width=\"678\" height=\"272\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/onclick-attribute.png 678w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/onclick-attribute-300x120.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/onclick-attribute-624x250.png 624w\" sizes=\"(max-width: 678px) 100vw, 678px\" \/><\/a><\/p>\n<p>The final markup for the topic looks like this:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;html xmlns:MadCap=\"http:\/\/www.madcapsoftware.com\/Schemas\/MadCap.xsd\" MadCap:lastBlockDepth=\"2\" MadCap:lastHeight=\"174\" MadCap:lastWidth=\"242\"&gt;\r\n    &lt;head&gt;\r\n        &lt;link href=\"Resources\/Stylesheets\/Styles.css\" rel=\"stylesheet\" type=\"text\/css\" \/&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;\r\n        &lt;h1&gt;Topic Title&lt;\/h1&gt;\r\n        &lt;p&gt;\r\n            &lt;script type=\"text\/javascript\"&gt;\/*&lt;![CDATA[*\/function slideContent(id) {\r\n    if ($('#' + id).css('display') == 'none') {\r\n        $('#' + id).slideDown('slow', function () { });\r\n    }\r\n    else {\r\n        $('#' + id).slideUp('slow', function () { });\r\n    }\r\n}\/*]]&gt;*\/&lt;\/script&gt;\r\n        &lt;\/p&gt;\r\n        &lt;p onclick=\"slideContent('show-hide')\"&gt;Expand\/Collapse&lt;\/p&gt;\r\n        &lt;p id=\"show-hide\" class=\"space\"&gt;Delete this text and replace it with your own content.&lt;\/p&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>When the target is built and the output is opened, the click behavior looks like this:<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/06\/expand-collapse.mp4\">expand-collapse<\/a><\/p>\n<p>Other relevant concepts:<\/p>\n<ul>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\" target=\"_blank\">JavaScript functions<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Statements\/if...else\" target=\"_blank\">JavaScript if..else<\/a><\/li>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/www.w3schools.com\/tags\/att_global_id.asp\" target=\"_blank\">HTML id attribute<\/a><\/li>\n<li><a href=\"http:\/\/api.jquery.com\/jQuery\/\" target=\"_blank\">$ (dollar sign) that means jQuery<\/a><\/li>\n<li><a href=\"http:\/\/api.jquery.com\/css\/\" target=\"_blank\">jQuery css() function<\/a><\/li>\n<li><a href=\"http:\/\/webhelp.madcapsoftware.com\/flare9\/Default.htm#Scripts\/Inserting_Scripts_into_Topics.htm\">Inserting Scripts into Topics<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MadCap Flare includes some show-and-hide controls for web-based outputs such as\u00a0Togglers\u00a0and Expanding Text. This blog has explored some alternatives for show-and-hide in the context of condition tags. Here is another option which uses jQuery to expand and collapse an element with a sliding animation. Sliding show-and-hide actions are simple tasks with jQuery. Two such functions&hellip; <a class=\"more-link\" href=\"https:\/\/tregner.com\/flare-blog\/show-and-hide-with-jquery-in-html5-output\/\">Continue reading <span class=\"screen-reader-text\">Show and Hide with jQuery in HTML5 Output<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[53,49,61,5,65],"_links":{"self":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/496"}],"collection":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":9,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"predecessor-version":[{"id":509,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/496\/revisions\/509"}],"wp:attachment":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}