<?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>RentWiz Blog &#187; tabs</title>
	<atom:link href="http://getrentwiz.com/blog/tag/tabs/feed/" rel="self" type="application/rss+xml" />
	<link>http://getrentwiz.com/blog</link>
	<description>Rental Listings Made Easy.</description>
	<lastBuildDate>Sat, 25 Apr 2009 02:23:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To: Select a tab from a URL using jQuery</title>
		<link>http://getrentwiz.com/blog/jquery-tab-select-from-url/</link>
		<comments>http://getrentwiz.com/blog/jquery-tab-select-from-url/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 18:54:59 +0000</pubDate>
		<dc:creator>Art Armstrong</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tabs]]></category>

		<guid isPermaLink="false">http://getrentwiz.com/blog/?p=37</guid>
		<description><![CDATA[The latest issue that I have run into and had to fix was trying to select a tab from the URL so that we had some dynamic control of what was shown when the page loaded. This was mainly a concern for a couple of pages where the page had to be reloaded or redirected [...]]]></description>
			<content:encoded><![CDATA[<h3>The latest issue that I have run into and had to fix was trying to select a tab from the URL so that we had some dynamic control of what was shown when the page loaded. This was mainly a concern for a couple of pages where the page had to be reloaded or redirected to after a action was performed.</h3>
<p>The <a title="jQuery Tabs" href="http://docs.jquery.com/UI/API/1.7.1/Tabs" target="_blank">tabs</a> that jQuery has made available are some of the most useful and powerful tools that I have used within a new web application for a long time but as with anything there are a few things that aren&#8217;t built in which need to be remedied.</p>
<p><img class="size-full wp-image-55 alignright" title="picture-1" src="http://getrentwiz.com/blog/wp/wp-content/uploads/2009/04/picture-1.png" alt="picture-1" width="300" height="94" /></p>
<p>The first thing we need to do is create the jQuery code and the HTML for the tabs, don&#8217;t forget to include the <a title="Download jQuery" href="http://docs.jquery.com/Downloading_jQuery" target="_blank">jQuery files</a>&#8230;</p>
<p>jQuery Tab Information</p>
<pre>$(function(){

// Initialize Tabs
$('#my-tabs').tabs();

});</pre>
<p>HTML tab code</p>
<pre>&lt;div id="my-tabs"&gt;
	&lt;ul&gt;
    		 &lt;li&gt;&lt;a href="#my-tabs-1"&gt;&lt;span&gt;One&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
    		 &lt;li&gt;&lt;a href="#my-tabs-2"&gt;&lt;span&gt;Two&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
    		 &lt;li&gt;&lt;a href="#my-tabs-3"&gt;&lt;span&gt;Three&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div id="my-tabs-1"&gt;
		&lt;p&gt;First tab is active by default&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id="my-tabs-2"&gt;
		&lt;p&gt;Second tab&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id="my-tabs-3"&gt;
		&lt;p&gt;Third tab&lt;/p&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<p>Now that we have the basics of the tabs set up you just have to add a little bit of code to check if a hash has been passed through the URL and then select that tab. The way that this would be called would be something like, although <em>it wont work</em>:</p>
<p>http://www.getrentwiz.com/test-tabs/index.html#2</p>
<p>So here is the code that will added below the tab initialization that will allow the tab to be selected.</p>
<pre>$(function(){

// Initialize Tabs
$('#my-tabs').tabs();

if(document.location.hash!='') {
        //get the index from URL hash
      	tabSelect = document.location.hash.substr(1,document.location.hash.length);
	$("#my-tabs").tabs('select',tabSelect-1);
}

});</pre>
<p>Now as you will see in the code that we subtract the number passed through the hash by 1, this is to accommodate the 0-based index that arrays use. So for example, passing 2 would return the select of 1, which is array[1], or the second tab. I hope this helps out a few people that ran into the same problem but I cant take all the credit, most of this was learned from Raymond Camden from <a title="O'Reilly InsideRIA" href="http://www.insideria.com/2009/03/playing-with-jquery-tabs.html" target="_blank">O&#8217;Reilly InsideRIA</a> and a few others.</p>
<p>Thanks for the interest!</p>
]]></content:encoded>
			<wfw:commentRss>http://getrentwiz.com/blog/jquery-tab-select-from-url/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

