{"id":148,"date":"2011-03-24T11:27:56","date_gmt":"2011-03-24T11:27:56","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=148"},"modified":"2011-03-24T11:30:04","modified_gmt":"2011-03-24T11:30:04","slug":"expand-collapse-jquery-part-2","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/expand-collapse-jquery-part-2\/","title":{"rendered":"Expand \/ Collapse with jQuery &#8211; Part II"},"content":{"rendered":"<p>Since my first post on the subject, I was introduced to a jQuery method called nextUntil(). I didn&#39;t realize the possibilities with this method until I got thinking about expand\/collapse again. Where previously, I was using a wrapper to enclose the expandables\/collapsables, that is no longer necessary.<\/p>\n<h3>The HTML<\/h3>\n<p><code>&lt;h3&gt;See this content?&lt;\/h3&gt;<br \/>\n\t&lt;p&gt;This is paragraph 1&lt;\/p&gt;<br \/>\n\t&lt;p&gt;This is paragraph 2&lt;\/p&gt;<br \/>\n\t&lt;ul&gt;<br \/>\n\t&nbsp; &lt;li&gt;This is a list&lt;\/li&gt;<br \/>\n\t&lt;\/ul&gt;<\/p>\n<p>\t<\/code><\/p>\n<h3>The jQuery<\/h3>\n<p><code>$(&#39;h3&#39;).nextUntil(&#39;h3&#39;).hide();<br \/>\n\t$(&#39;h3&#39;).prepend(&#39;&lt;span&gt;+ &lt;\/span&gt;&#39;).css(&#39;cursor&#39;, &#39;pointer&#39;);<br \/>\n\t$(&#39;h3&#39;).click(function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).nextUntil(&#39;h3&#39;).slideToggle(&#39;fast&#39;);<br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).toggleClass(&#39;expanded&#39;);<br \/>\n\t&nbsp;&nbsp;&nbsp; ($(this).children(&#39;span&#39;).html() == &#39;+ &#39;) ?<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(this).children(&#39;span&#39;).html(&#39;- &#39;) :<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(this).children(&#39;span&#39;).html(&#39;+ &#39;);<br \/>\n\t});<br \/>\n\t<\/code><\/p>\n<p>I even decided to include a little css directly in the jQuery, to make this technique even more &quot;plug-n-play&quot; into any given site.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since my first post on the subject, I was introduced to a jQuery method called nextUntil(). I didn&#39;t realize the possibilities with this method until&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":[12,5],"tags":[8,9],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/148"}],"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=148"}],"version-history":[{"count":2,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":150,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions\/150"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}