<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Skull Jackpot &#187; accordion</title>
	<atom:link href="http://skulljackpot.com/tagged-as/accordion/feed/" rel="self" type="application/rss+xml" />
	<link>http://skulljackpot.com</link>
	<description>Various thoughts of minimal interest to others</description>
	<lastBuildDate>Fri, 25 Feb 2011 16:22:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quick and dirty (but useful) jQuery accordion pattern</title>
		<link>http://skulljackpot.com/2009/03/30/quick-and-dirty-but-useful-jquery-accordion-pattern/</link>
		<comments>http://skulljackpot.com/2009/03/30/quick-and-dirty-but-useful-jquery-accordion-pattern/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 22:42:05 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Quick and Dirty]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://skulljackpot.com/?p=45</guid>
		<description><![CDATA[It's fairly common to want to have multiple panels on a page, only one of which should be visible at any given moment. There are too many jQuery accordion examples to count. I recently knocked together a handy general case, which includes a novel piece of functionality. What makes this one different? You can specify an arbitrary panel to be expanded upon page load, without any server-side code.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s fairly common to want to have multiple panels on a page, only one of which should be visible at any given moment. There are too many jQuery accordion examples to count. I recently knocked together a handy general case, which includes a novel piece of functionality. What makes this one different? You can specify an arbitrary panel to be expanded upon page load, without any server-side code.</p>
<h2>The HTML</h2>
<pre>
&lt;div class="expand"&gt;
&lt;h2 id="expand-an-element" class="toggler"&gt;This will be clickable, once the javascript runs&lt;/h2&gt;
&lt;div class="togglee"&gt;
  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sapien. Phasellus nunc. Vestibulum consectetur tortor eu urna. Donec quam. Vivamus id neque a nisl iaculis vulputate.&lt;/p&gt;
  &lt;p&gt;Multiple elements can be contained within the &lt;code&gt;togglee&lt;/code&gt; parent.&lt;/p&gt;
&lt;/div&gt;&lt;!-- /.togglee --&gt;
&lt;h2 id="expand-this-element" class="toggler"&gt;Another toggler element&lt;/h2&gt;
&lt;div class="togglee"&gt;
  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sapien. Phasellus nunc. Vestibulum consectetur tortor eu urna. Donec quam. Vivamus id neque a nisl iaculis vulputate.&lt;/p&gt;
&lt;/div&gt;&lt;!-- /.togglee --&gt;
&lt;/div&gt;&lt;!-- /.expand --&gt;
</pre>
<p><strong>Note</strong>: the <code>expand</code>, <code>toggler</code>, and <code>togglee</code> elements aren&#8217;t limited to the example above &#8211; they can be any valid HTML element. The only assumptions are that the <code>expand</code> will be a parent, and that each <code>toggler</code> immediately precedes the associated <code>togglee</code> element.</p>
<h2>The CSS</h2>
<pre>.expandable .toggler {
cursor: pointer;
}

.expandable .togglee {
display: none;
}</pre>
<p>You can also apply styles to the toggler element by targeting the <code>expanded</code> class. This will only be added to togglers which are currently expanded, which allows you to provide visual cues about the fact that it&#8217;s an active interface element.</p>
<h2>The javascript</h2>
<pre>$(document).ready(function(){
  $('.expand').addClass('expandable');
  $('.expandable .toggler').click(function() {
    var target =  $(this).next('.togglee');
    if (target.is(':hidden')) {
      var togglees = $('.togglee');
      for (i=0;i&lt;togglees.length;i++){
        $(togglees[i]).slideUp().prev('.toggler').removeClass('expanded');
      }
      $(target).slideDown().prev('.toggler').addClass('expanded');
    }
  });
  var initialExpansion = "";
  if(document.location.hash) initialExpansion = $(unescape(document.location.hash));
  if(!(initialExpansion.length)) initialExpansion = $('.expandable .toggler:first');
  initialExpansion.addClass('expanded').next('.togglee').css("display","block");
});</pre>
<p>We use <code>document.location.hash</code> to access the portion of the URL beginning at the hash sign (#). Then, if there are any elements with a corresponding <code>id</code>, we apply our expand logic there (falling through to showing the first panel if there isn&#8217;t a match).</p>
<p>This allows us to construct links like <code>http://example.com/path/to/page#expand-this-element</code>, and have that panel begin in an expanded state.</p>
<p>Use and enjoy. If you have feedback or improvements you&#8217;d like to see, note &#8216;em in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://skulljackpot.com/2009/03/30/quick-and-dirty-but-useful-jquery-accordion-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.179 seconds -->

