{"id":670,"date":"2012-07-05T11:58:52","date_gmt":"2012-07-05T11:58:52","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=670"},"modified":"2012-07-05T11:58:52","modified_gmt":"2012-07-05T11:58:52","slug":"collapsing-list-content","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/collapsing-list-content\/","title":{"rendered":"Collapsing list content"},"content":{"rendered":"<p>If you keep up with my posts, you&#39;ll know I&#39;m a big fan of graceful degradation when it comes to JavaScript. For me, graceful degradation means two things:<\/p>\n<ol>\n<li>Happier non-javascript users<\/li>\n<li>Happier search engines<\/li>\n<\/ol>\n<p>A search engine is like a non-javascript user in many ways, as it crawls content without applying any javascript (or css) to it.<\/p>\n<p>With that aside, I thought I&#39;d toss out another method of collapsing content while adhering to rules of graceful degradation. Sometimes we find our unordered or ordered lists get a little lengthy. Instead of paginating or truncating them, you can &quot;collapse&quot; them with just a few lines of jQuery:<\/p>\n<p><code>$(&#39;ul&#39;).each(function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; if($(this).find(&#39;li&#39;).length &gt; 1)<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(this).find(&#39;li:first&#39;).<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; append(&#39;&lt;span&gt;more&amp;hellip;&lt;\/span&gt;&#39;).<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; siblings().hide();<br \/>\n\t});<\/p>\n<p>\t$(&#39;li span&#39;).click(function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).parent().siblings().toggle();<br \/>\n\t});<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you keep up with my posts, you&#39;ll know I&#39;m a big fan of graceful degradation when it comes to JavaScript. For me, graceful degradation&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":[183],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/670"}],"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=670"}],"version-history":[{"count":1,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/670\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/670\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}