{"id":322,"date":"2011-07-29T11:32:32","date_gmt":"2011-07-29T11:32:32","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=322"},"modified":"2011-07-29T11:32:32","modified_gmt":"2011-07-29T11:32:32","slug":"simple-jquery-tabbed-content","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/simple-jquery-tabbed-content\/","title":{"rendered":"Simple jQuery Tabbed Content"},"content":{"rendered":"<p>Goal: Produce a simple, small script which gracefully degrades without JavaScript.<\/p>\n<p>Note: The HTML below is pulled from a Zope Page Template (with embedded Python), but the code should be easy to dissect.<\/p>\n<h3>HTML<\/h3>\n<p><code>&lt;div id=&quot;tabbed-content&quot; tal:define=&quot;currentTab request\/tab|string:cabinets&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div class=&quot;tabs-wrapper&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;ul class=&quot;tabs&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;li tal:attributes=&quot;class python: test(request.get(&#39;tab&#39;,&#39;&#39;) in [&#39;cabinets&#39;, &#39;&#39;], &#39;selected&#39;, &#39;&#39;)&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href=&quot;?tab=cabinets#content&quot; id=&quot;tab-cabinets&quot;&gt;Cabinets&lt;\/a&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/li&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;li tal:attributes=&quot;class python: test(request.get(&#39;tab&#39;,&#39;&#39;) == &#39;gallery&#39;, &#39;selected&#39;, &#39;&#39;)&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href=&quot;?tab=gallery#content&quot; id=&quot;tab-gallery&quot;&gt;Gallery&lt;\/a&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/li&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;li tal:attributes=&quot;class python: test(request.get(&#39;tab&#39;,&#39;&#39;) == &#39;specs&#39;, &#39;selected&#39;, &#39;&#39;)&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href=&quot;?tab=specs#content&quot; id=&quot;tab-specs&quot;&gt;Specifications&lt;\/a&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/li&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;\/ul&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div class=&quot;visualClear&quot;&gt;&lt;!-- --&gt;&lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div id=&quot;cabinets&quot; class=&quot;tab-body&quot; tal:attributes=&quot;class python: test(currentTab == &#39;cabinets&#39;, &#39;tab-body&#39;, &#39;tab-body initial-hide&#39;)&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; content here...<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div id=&quot;gallery&quot; class=&quot;tab-body&quot; tal:attributes=&quot;class python: test(currentTab == &#39;gallery&#39;, &#39;tab-body&#39;, &#39;tab-body initial-hide&#39;)&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; content here...<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div id=&quot;specs&quot; class=&quot;tab-body&quot; tal:attributes=&quot;class python: test(currentTab == &#39;specs&#39;, &#39;tab-body&#39;, &#39;tab-body initial-hide&#39;)&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; content here...<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&lt;\/div&gt;<br \/>\n\t<\/code><\/p>\n<h3>\n\tCSS<\/h3>\n<p><code>.tabs-wrapper { margin-bottom: 1em; border-bottom: 1px solid #bbb; }<br \/>\n\t.tabs { margin: 0 !important; padding: 7px 0 0 8px; list-style-type: none; list-style-image: none; }<br \/>\n\t.tabs li { float: left; display: block; margin: 0 5px -1px 0; padding: 0; font-size: 12px; }<br \/>\n\t.tabs li a { padding: 3px 8px 1px 8px; font-weight: bold; color: #444 !important; outline: none !important;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; border: 1px solid #e0e0e0; border-radius: 5px 5px 0 0; background: #e0e0e0; }<br \/>\n\t.tabs li.selected { position: relative; margin-top: -2px; top: 2px; }<br \/>\n\t.tabs li.selected a { padding-bottom: 3px; border: 1px solid #bbb; border-bottom: 0; background: #fff; }<br \/>\n\t.initial-hide { display: none; }<br \/>\n\t.visualClear { clear: both; }<br \/>\n\t<\/code><\/p>\n<h3>\n\tjQuery<\/h3>\n<p><code>$(&#39;.tabs a&#39;).click(function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; var activateId = jq(this).attr(&#39;id&#39;).substring(4); \/\/ get id of tab &quot;body&quot;<br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).parent().siblings().removeClass(&#39;selected&#39;);<br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).parent().addClass(&#39;selected&#39;);<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).parent().parent().parent().siblings().hide(); \/\/ hide all tab bodies<br \/>\n\t&nbsp;&nbsp;&nbsp; $(&#39;#&#39; + activateId).show(); \/\/ show only the selected tab body<br \/>\n\t&nbsp;&nbsp;&nbsp; return false;<br \/>\n\t});&nbsp;&nbsp;&nbsp; <br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: Produce a simple, small script which gracefully degrades without JavaScript. Note: The HTML below is pulled from a Zope Page Template (with embedded Python),&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":[37],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/322"}],"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=322"}],"version-history":[{"count":0,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}