{"id":6,"date":"2011-01-30T14:20:42","date_gmt":"2011-01-30T14:20:42","guid":{"rendered":"http:\/\/sitekicker.uwsweb.com\/blog\/?p=6"},"modified":"2011-02-13T00:12:02","modified_gmt":"2011-02-13T00:12:02","slug":"expand-collapse-javascript-jquery","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/expand-collapse-javascript-jquery\/","title":{"rendered":"Expand \/ Collapse with JavaScript \/ jQuery"},"content":{"rendered":"<p>If your page content is getting lengthy or you just want to add some interactivity to your site, consider expandable\/collapsible content. We can leverage the JavaScript toolkit, <a href=\"http:\/\/jquery.com\/\">jQuery<\/a> to make this process painless.<\/p>\n<p><code><strong>The HTML<\/strong> <br \/>\n\t&lt;div class=&quot;expandable&quot;&gt;<br \/>\n\t&nbsp; &lt;h3&gt;See this content?&lt;\/h3&gt;<br \/>\n\t&nbsp; &lt;p&gt;This is paragraph 1&lt;\/p&gt;<br \/>\n\t&nbsp; &lt;p&gt;This is paragraph 2&lt;\/p&gt;<br \/>\n\t&nbsp; &lt;ul&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;li&gt;This is a list&lt;\/li&gt;<br \/>\n\t&nbsp; &lt;\/ul&gt;<br \/>\n\t&lt;\/div&gt;<\/code><\/p>\n<p><strong>The JavaScript \/ jQuery<br \/>\n\t<\/strong><code>$(&#39;.expandable&#39;).children().not(&#39;h3&#39;).hide();<br \/>\n\t$(&#39;.expandable&#39;).children(&#39;h3&#39;).prepend(&#39;&lt;span&gt;+&lt;\/span&gt;&#39;);<br \/>\n\t$(&#39;.expandable&#39;).children(&#39;h3&#39;).click(function() { <br \/>\n\t&nbsp; $(this).siblings().slideToggle(&#39;fast&#39;); <br \/>\n\t&nbsp; $(this).parent().toggleClass(&#39;expanded&#39;);<br \/>\n\t&nbsp; ($(this).children(&#39;span&#39;).html() == &#39;+&#39;) ? <br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).children(&#39;span&#39;).html(&#39;-&#39;) : <br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).children(&#39;span&#39;).html(&#39;+&#39;);<br \/>\n\t});<\/code><\/p>\n<p><strong>The CSS<br \/>\n\t<\/strong><code>.expandable h3 { cursor: pointer; }<br \/>\n\t.expandable h3 span { <\/code><code><br \/>\n\t&nbsp; display: block;<br \/>\n\t&nbsp; float: left;<br \/>\n\t&nbsp; width: 10px;<br \/>\n\t&nbsp; margin-left: -10px;<br \/>\n\t&nbsp; color: #a00; <\/code><code><br \/>\n\t}<br \/>\n\t.expanded { \/\/ whatever styles you like (applied when element is &quot;expanded&quot;) }<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If your page content is getting lengthy or you just want to add some interactivity to your site, consider expandable\/collapsible content. We can leverage the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[5],"tags":[7,6,8,9],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/6"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":12,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}