<?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>Kyle Schaeffer - Interactive Media Design &#187; JavaScript</title>
	<atom:link href="http://kyleschaeffer.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://kyleschaeffer.com</link>
	<description>Veteran web designer Kyle Schaeffer brings you tips, tricks, and best practices in interactive media design.</description>
	<lastBuildDate>Thu, 15 Jul 2010 21:26:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Input Prompt Text:  A Better Way</title>
		<link>http://kyleschaeffer.com/best-practices/input-prompt-text/</link>
		<comments>http://kyleschaeffer.com/best-practices/input-prompt-text/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 02:43:37 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Text]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=565</guid>
		<description><![CDATA[It&#8217;s a very cool feature to have a form field that has prompt text such as Enter search keywords&#8230; right inside the input box, itself. It looks good, it makes sense to users, and it can save a lot of real estate in your design by negating the need for field labels. The problem, however, [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a very cool feature to have a form field that has prompt text such as <em>Enter search keywords&#8230;</em> right inside the input box, itself. It looks good, it makes sense to users, and it can save a lot of real estate in your design by negating the need for field labels. The problem, however, is that there are about one hundred ways to implement prompt text, and ninety-nine of them are wrong. Let&#8217;s look at this thing from all angles and come up with a fantastically simple and reliable way to make this work.<span id="more-565"></span></p>
<h3>What is input prompt text?</h3>
<p>You&#8217;re probably familiar with the concept, even if you don&#8217;t know what I&#8217;m talking about. Here&#8217;s an example:</p>
<p>
<input type="text" style="color: #999; font-style: italic; width: 250px;" value="Enter search keywords..." />
<input type="button" value="Search" /></p>
<p>The <em>prompt text</em> appears inside the form field as soon as the page loads, so users immediately know what it&#8217;s for. Simple, right?</p>
<h3>Why it Doesn&#8217;t Work</h3>
<p>There are a number of problems you&#8217;ll encounter while implementing prompt text into your forms. Watch out for these caveats when you&#8217;re developing your own solution.</p>
<ol>
<li><strong>Input validation</strong> &mdash; if someone submits the form without first removing the prompt text, your prompt text is submitted in lieu of real data. Fixing this is a pain. Avoiding this entirely is recommended.</li>
<li><strong>Prompt style</strong> &mdash; it&#8217;s best to style the prompt text so that it doesn&#8217;t look like real form data. Creativity is a virtue, but generally web users will expect light (gray) text and italics. This can be problematic because you&#8217;ll have to swap the input style back and forth using JavaScript.</li>
<li><strong>Losing focus</strong> &mdash; when users focus on a form field, don&#8217;t type anything, and then click somewhere else, you should always add the prompt text <em>back into the input box</em>.  Otherwise, users could miss the intent of the form field entirely.  Again, you&#8217;ll have to do this with JavaScript, which can be a little tricky.</li>
<li><strong>Progressive enhancement</strong> &mdash; always make sure that users without JavaScript can still understand and interact with your form fields. This is progressive enhancement at its finest.</li>
</ol>
<h3>The Solution</h3>
<p>Almost everything related to the problems listed above originates from one basic fact: you&#8217;re trying to create both a <strong>field</strong> and a <strong>label</strong> using a single HTML element. When you take a step back and think about that, it really doesn&#8217;t make much sense, does it? The solution lies in separating the form field from the label entirely. We&#8217;ll use a little bit of jQuery to create an elegant solution that dynamically creates these labels and places them over our form fields. Because we&#8217;re creating two separate elements, we can use CSS to style them independently. Perfect!</p>
<p><strong>The jQuery:</strong></p>
<pre>$(document).ready(function(){
  $('input[type=text][title],input[type=password][title],textarea[title]').each(function(i){
    $(this).addClass('input-prompt-' + i);
    var promptSpan = $('&lt;span class=&quot;input-prompt&quot;/&gt;');
    $(promptSpan).attr('id', 'input-prompt-' + i);
    $(promptSpan).append($(this).attr('title'));
    $(promptSpan).click(function(){
      $(this).hide();
      $('.' + $(this).attr('id')).focus();
    });
    if($(this).val() != ''){
      $(promptSpan).hide();
    }
    $(this).before(promptSpan);
    $(this).focus(function(){
      $('#input-prompt-' + i).hide();
    });
    $(this).blur(function(){
      if($(this).val() == ''){
        $('#input-prompt-' + i).show();
      }
    });
  });
});</pre>
<p><strong>The CSS:</strong></p>
<pre>.input-prompt {
  position: absolute;
  font-style: italic;
  color: #aaa;
  margin: 0.2em 0 0 0.5em;
}</pre>
<p><strong>The HTML:</strong></p>
<pre>&lt;input type=&quot;text&quot; <strong>title=&quot;Enter search keywords...&quot;</strong> /&gt;</pre>
<p>Basically, this script finds any <code>&lt;input&gt;</code> tags that have a <code>title</code> attribute (i.e. <code>&lt;input title=&quot;Enter search keywords...&quot; /&gt;</code>). For each of these form fields, it takes the <code>title</code> and creates a little <code>&lt;span&gt;</code> tag next to it. The CSS positions the <code>&lt;span&gt;</code> tag so that it appears <em>on top</em> of the form field. The rest is just a little bit of scripting that makes sure to hide and show the labels based on what the user is doing with the input box.</p>
<h3>The Result</h3>
<p>Here is a demo of the code shown above:</p>
<p><script type="text/javascript">$(document).ready(function(){
  $('input#demo').each(function(i){
    $(this).addClass('input-prompt-' + i);
    var promptSpan = $('<span class="input-prompt"/>');
    $(promptSpan).attr('id', 'input-prompt-' + i);
    $(promptSpan).append($(this).attr('title'));
    $(promptSpan).click(function(){
      $(this).hide();
      $('.' + $(this).attr('id')).focus();
    });
    if($(this).val() != ''){
      $(promptSpan).hide();
    }
    $(this).before(promptSpan);
    $(this).focus(function(){
      $('#input-prompt-' + i).hide();
    });
    $(this).blur(function(){
      if($(this).val() == ''){
        $('#input-prompt-' + i).show();
      }
    });
  });
});</script><br />
<style type="text/css">.input-prompt { position: absolute; font-style: italic; color: #aaa; margin: 0.7em 0 0 1em; }</style>
<input id="demo" type="text" title="Enter search keywords..." size="50" style="padding: 0.5em;" />
<p>Users without JavaScript enabled will see the normal title tool tips when they hover their mouse cursor over the form field.  Please note that you&#8217;ll probably have to adjust the <code>margin</code> a bit in the CSS to make sure the labels fit the size of your input boxes. For more information on jQuery and all the great things it can do, visit <a href="http://jquery.com/">jQuery.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/best-practices/input-prompt-text/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Perfect jQuery AJAX Request</title>
		<link>http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/</link>
		<comments>http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 14:10:41 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=538</guid>
		<description><![CDATA[If you&#8217;re into client-scripting, then jQuery AJAX is probably your thing (if it&#8217;s not, perhaps it should be!). jQuery has some fantastic support for AJAX, and implementing it into your web application is so easy it&#8217;s stupid. The AJAX functionality in the AJAX library is so flexible, sometimes it&#8217;s easy to get lost when you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re into client-scripting, then <a href="http://api.jquery.com/category/ajax/">jQuery AJAX</a> is probably <em>your thing</em> (if it&#8217;s not, perhaps it should be!). jQuery has some fantastic support for AJAX, and implementing it into your web application is so easy it&#8217;s stupid.  The AJAX functionality in the AJAX library is so flexible, sometimes it&#8217;s easy to get lost when you&#8217;re trying to do something very simple.  I&#8217;ve come up with a very basic jQuery AJAX template that I use for just about everything I do, and I thought it might be useful to share.<span id="more-538"></span></p>
<h3>The Old Way</h3>
<p>Did you work with AJAX <em>way back when</em>, when it first came out?  You might remember that an AJAX request looked a little like this.</p>
<pre>var xmlhttp;
xmlhttp = GetXmlHttpObject();
if(xmlhttp == null){
  alert(&quot;Boo! Your browser doesn't support AJAX!&quot;);
  return;
}
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open(&quot;GET&quot;, &quot;http://www.google.com&quot;, true);
xmlhttp.send(null);

function stateChanged(){
  if(xmlhttp.readyState == 4){
    // do something with the response text
    alert(xmlhttp.responseText);
  }
}
function GetXmlHttpObject(){
  // IE7+, Firefox, Chrome, Opera, Safari
  if(window.XMLHttpRequest){
    return new XMLHttpRequest();
  }

  //IE5, IE6
  if(window.ActiveXObject){
    return new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
  }
  return null;
}</pre>
<p>In a nutshell, that sucks!  All of that code to simply request the contents of Google&#8217;s home page, and then alert in the window.  That&#8217;s not very helpful at all.  Alternatively, here is the exact same function written in jQuery:</p>
<pre>$.ajax({
  url: 'http://www.google.com',
  success:function(data){
    alert(data);
  }
});</pre>
<p>As you can plainly see, the jQuery AJAX method is much easier to wrap your mind around.  You give it a URL to request, and then you give it a set of instructions if a successful request is made.  Easy!</p>
<p>I understand that it&#8217;s not very useful to request the contents of a web page and alert it to your users (in fact, that&#8217;s probably pretty annoying), so let&#8217;s take it up a notch.  jQuery AJAX features a ridiculous amount of customization options, events, and the like to give you a huge amount of flexibility, and it can be hard to find a good place to start.  I&#8217;ll help you find the starting line, and you can take it from there.</p>
<h3>The Perfect AJAX Request</h3>
<p>I&#8217;m fairly positive that by using the term <em>perfect</em>, I&#8217;m going to get a good amount of nay-sayers telling me why jQuery AJAX sucks, but that&#8217;s not what I&#8217;m getting at.  This jQuery function is <em>perfect</em> in the sense that it handles 99% of all the AJAX requests you&#8217;ll ever need to make, it includes a success and failure function to ensure that users get the proper feedback they need, and you&#8217;ll get a spinning loading image while the request is being processed to boot.  Throw on top of that the fact that it&#8217;s extremely easy to use, and I&#8217;d say you have something that&#8217;s pretty damned close to perfect, at least in my book.  Here is the template:</p>
<pre>$.ajax({
  type: 'POST',
  url: '<strong>http://www.kyleschaeffer.com/feed/</strong>',
  data: { <strong>postVar1: 'theValue1', postVar2: 'theValue2'</strong> },
  beforeSend:function(){
    // this is where we append a loading image
    $('#ajax-panel').html('&lt;div class=&quot;loading&quot;&gt;&lt;img src=&quot;<strong>/images/loading.gif</strong>&quot; alt=&quot;Loading...&quot; /&gt;&lt;/div&gt;');
  },
  success:function(data){
    // successful request; do something with the data
    $('#ajax-panel').empty();
    $(data).find('item').each(function(i){
      $('#ajax-panel').append('<strong>&lt;h4&gt;' + $(this).find('title').text() + '&lt;/h4&gt;&lt;p&gt;' + $(this).find('link').text() + '&lt;/p&gt;</strong>');
    });
  },
  error:function(){
    // failed request; give feedback to user
    $('#ajax-panel').html('&lt;p class=&quot;error&quot;&gt;&lt;strong&gt;Oops!&lt;/strong&gt; Try that again in a few moments.&lt;/p&gt;');
  }
});</pre>
<p>In this case, I&#8217;m loading my site&#8217;s RSS feed into a <code>&lt;div/&gt;</code> with an ID of <code>ajax-panel</code>.  What does it look like exactly, you ask?  Let&#8217;s try it out.</p>
<style type="text/css">#ajax-panel { background: #f5f5f5; border: 1px #ddd solid; padding: 20px; margin: 0 0 5px 0; } .loading { padding: 50px 0; text-align: center; }</style>
<div id="ajax-panel"></div>
<div class="ajax-panel-actions">
<input id="load-feed" type="button" value="Load the RSS feed now!" />
<input id="load-feed-fail" type="button" value="Try a FAILED AJAX Request" /></div>
<p><script type="text/javascript" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/04/the-perfect-ajax.js"></script></p>
<h3>Data Types</h3>
<p>We&#8217;re loading an RSS feed in this example, so the AJAX function is designed to interpret XML data. jQuery AJAX also understands a number of other data formats, such as HTML, plain text, and even JSON. Find out more about data types at the <a href="http://api.jquery.com/jQuery.ajax/">jQuery AJAX documentation page</a>.</p>
<h3>Loading Image</h3>
<p>Did you notice the spinning loading image? In the <code>beforeSend</code> function, we&#8217;re appending a loading image to our AJAX panel, and we&#8217;re then taking it out when a request has completed.  If you&#8217;re not already aware, be sure to check out the very handy website, <a href="http://www.ajaxload.info/">Ajaxload</a>.  This site allows you to quickly create <em>spinner</em> images of any size and color. They have an impressive array of bars, circles, flowers, and the like, so all your design needs should be satiated by the array of options they provide.  It&#8217;s always a good idea to include a loading image when working with AJAX requests &mdash; depending on the client&#8217;s connection speed and a number of other variables, the time it takes to complete a request can vary.  Don&#8217;t assume it will be lickity-split and lightning fast every time.  Give your users some feedback to let them know that you&#8217;re working on it.</p>
<h3>POST Data</h3>
<p>You may have noticed that we&#8217;re using <code>POST</code> as the request type.  <code>POST</code> requests works just like <code>GET</code> requests, except you get the added flexibility to also send data and other variables along with your request.  We sent some dummy data that isn&#8217;t used by the RSS feed (<code>data: { postVar1: 'theValue1', postVar2: 'theValue2' }</code>), so feel free to change or omit this line of code in order to customize your AJAX request function. As an example, you could send a variable like <code>userId: '45'</code> to a custom PHP script that in return sends you information about a particular user. The possibilities are endless!</p>
<h3>Remember the Search</h3>
<p>Take what you&#8217;ve learned and venture into the wide world of web development armed with the knowledge you now possess.  Destroy post-backs wherever they may live, and always remember that Google hates AJAX and won&#8217;t interpret anything on your page that&#8217;s loaded via script!  Good luck, and happy styling.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create a Lightbox with jQuery and CSS</title>
		<link>http://kyleschaeffer.com/tutorials/lightbox-jquery-css/</link>
		<comments>http://kyleschaeffer.com/tutorials/lightbox-jquery-css/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 21:37:05 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=488</guid>
		<description><![CDATA[The &#8220;lightbox&#8221; is a unique and useful design tool when used properly. It allows designers to present information that is totally independent from the site theme, and it is especially useful when displaying information that is loaded via AJAX requests (often negating the need for additional post-backs on your pages). There are countless ways to [...]]]></description>
			<content:encoded><![CDATA[<p>The &#8220;lightbox&#8221; is a unique and useful design tool when used properly. It allows designers to present information that is totally independent from the site theme, and it is especially useful when displaying information that is loaded via AJAX requests (often negating the need for additional post-backs on your pages). There are countless ways to implement lightbox functionality into your site, and almost every option I&#8217;ve ever seen is weighed down by extraneous functionality or useless transition animations. It&#8217;s quite easy to create your own lightboxes with minimal effort. This tutorial can serve as a quick and easy template to get you started.<span id="more-488"></span></p>
<h3>The CSS Style</h3>
<p>There are <em>two</em> elements you&#8217;ll have to implement into your design in order to create a lightbox — CSS and Javascript. We&#8217;ll take care of the CSS style first, as it&#8217;s the most simple to implement. On your page or in an attached style sheet, add the following CSS styles:</p>
<pre>#lightbox {
	position: absolute;
	top: 0;
	left: 50%;
	width: 500px;
	margin-left: -250px;
	background: #fff;
	z-index: 1001;
	display: none;
}
#lightbox-shadow {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: #000;
	filter: alpha(opacity=75);
	-moz-opacity: 0.75;
	-khtml-opacity: 0.75;
	opacity: 0.75;
	z-index: 1000;
	display: none;
}</pre>
<p><strong>What we just did:</strong> we established two styles. One style is for the lightbox that actually appears on the page (<code>#lightbox</code>). The second style is for lightbox background (<code>#lightbox-shadow</code>). We have made this background dark and semi-transparent in order to dim the site&#8217;s content as it appears behind the lightbox.</p>
<h3>The jQuery Script</h3>
<p>The real work is done via our simple jQuery script. We have two JavaScript functions that will handle displaying and hiding our lightbox. First, make sure you have attached the jQuery library to your page:</p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;</pre>
<p>Now, in an attached <code>.js</code> file, add the following script code.</p>
<pre>/****************************************
	Barebones Lightbox Template
	by Kyle Schaeffer
	kyleschaeffer.com
	* requires jQuery
****************************************/

// display the lightbox
function lightbox(insertContent, ajaxContentUrl){

	// add lightbox/shadow &lt;div/&gt;'s if not previously added
	if($('#lightbox').size() == 0){
		var theLightbox = $('&lt;div id=&quot;lightbox&quot;/&gt;');
		var theShadow = $('&lt;div id=&quot;lightbox-shadow&quot;/&gt;');
		$(theShadow).click(function(e){
			closeLightbox();
		});
		$('body').append(theShadow);
		$('body').append(theLightbox);
	}

	// remove any previously added content
	$('#lightbox').empty();

	// insert HTML content
	if(insertContent != null){
		$('#lightbox').append(insertContent);
	}

	// insert AJAX content
	if(ajaxContentUrl != null){
		// temporarily add a &quot;Loading...&quot; message in the lightbox
		$('#lightbox').append('&lt;p class=&quot;loading&quot;&gt;Loading...&lt;/p&gt;');

		// request AJAX content
		$.ajax({
			type: 'GET',
			url: ajaxContentUrl,
			success:function(data){
				// remove &quot;Loading...&quot; message and append AJAX content
				$('#lightbox').empty();
				$('#lightbox').append(data);
			},
			error:function(){
				alert('AJAX Failure!');
			}
		});
	}

	// move the lightbox to the current window top + 100px
	$('#lightbox').css('top', $(window).scrollTop() + 100 + 'px');

	// display the lightbox
	$('#lightbox').show();
	$('#lightbox-shadow').show();

}

// close the lightbox
function closeLightbox(){

	// hide lightbox and shadow &lt;div/&gt;'s
	$('#lightbox').hide();
	$('#lightbox-shadow').hide();

	// remove contents of lightbox in case a video or other content is actively playing
	$('#lightbox').empty();
}</pre>
<link rel="stylesheet" type="text/css" href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.css" />
<style type="text/css">#lightbox-shadow { position: fixed; } #lightbox { font-size: 2em; padding: 20px; margin-left: -270px; }</style>
<p><script type="text/javascript" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.js"></script><br />
<h3>Ready for Lightboxing</h3>
<p>Once you have the CSS and script into place, you can call your new <code>lightbox();</code> function from anywhere within your design. It&#8217;s as easy as calling the lightbox from an <code>anchor</code> tag:</p>
<pre>&lt;a href=&quot;javascript:lightbox('Hello!');&quot;&gt;Show me the lightbox&lt;/a&gt;</pre>
<p>Remember, clicking anywhere on the &#8220;shadow&#8221; <code>&lt;div/&gt;</code> will hide the lightbox &mdash; you could easily add a &#8220;close&#8221; button to your lightbox by connecting it to the <code>closeLightbox();</code> JavaScript function.</p>
<p>Similarly, you can insert HTML (or even a jQuery DOM object) into the lightbox. Like so:</p>
<pre>&lt;a href=&quot;javascript:lightbox('&lt;p&gt;&lt;strong&gt;Rich&lt;/strong&gt; content works too!&lt;/p&gt;');&quot;&gt;Show me the lightbox&lt;/a&gt;</pre>
<p>Finally, you can even use this simple lightbox function to insert AJAX content. Please keep in mind that my JavaScript function simply inserts the entire result into the <code>#lightbox</code> element &mdash; if you&#8217;re trying to request a website or HTML page, you&#8217;ll probably have to remove the <code>&lt;html/&gt;</code> and <code>&lt;body/&gt;</code> tags before inserting content into your lightbox window, else the lightbox would simply disappear. An AJAX lightbox request looks a little like this:</p>
<pre>&lt;a href=&quot;javascript:lightbox(null, 'http://foo.com/readme.txt');&quot;&gt;Show me the lightbox&lt;/a&gt;</pre>
<h3>The Demo</h3>
<ul>
<li><strong>Try it out:</strong> <a href="javascript:lightbox('How elegantly simple! This is a barebones lightbox if I ever saw one. Click on the dark shaded background to close the lightbox.');">Show me the lightbox</a></li>
<li><strong>Let&#8217;s load some AJAX content:</strong> <a href="javascript:lightbox(null, 'http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.css');">Load the CSS file for this tutorial into a lightbox</a></li>
</ul>
<p>If you&#8217;re on a fast connection, you may not notice, but the AJAX link actually reads &#8220;Loading&#8230;&#8221; in the lightbox a split-second before the content actually appears.  This can be useful to give users feedback while the AJAX request is processing. Please note that I&#8217;ve added a bit of styling to my demo (namely padding on the lightbox to make it appear less cluttered).</p>
<h3>Make it Shine</h3>
<p>You&#8217;ll probably want to modify the CSS and other elements of this lightbox in order to suit your site&#8217;s design and style. If you&#8217;re working with a lot of AJAX content, you may want to even replace the temporary <code>loading</code> element with an animated spinner image, or something of the like.</p>
<p>To help you get started, you can download the CSS and JavaScript referenced in this tutorial here:</p>
<ul>
<li><a href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.css">lightbox.css</a></li>
<li><a href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.js">lightbox.js</a></li>
</ul>
<p>Good luck, and happy styling!</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/tutorials/lightbox-jquery-css/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>IE Corner Inserts via jQuery</title>
		<link>http://kyleschaeffer.com/tutorials/ie-corner-inserts-via-jquery/</link>
		<comments>http://kyleschaeffer.com/tutorials/ie-corner-inserts-via-jquery/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 22:51:43 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Corners]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=422</guid>
		<description><![CDATA[I recently had a client whose design demanded rounded corners in a lot of different areas of their site. As I looked through the design documentation, the variety and color of these rounded widgets really started to add up. I quickly decided that pure CSS corners were the best choice for their design. Most users [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a client whose design demanded rounded corners in a lot of different areas of their site. As I looked through the design documentation, the variety and color of these rounded widgets really started to add up. I quickly decided that <a href="http://www.kyleschaeffer.com/best-practices/rounded-corners-in-mozilla-and-safari/">pure CSS corners</a> were the best choice for their design. Most users can utilize <code>border-radius</code> to apply the rounded effect without any overhead (the browser does the work), and the remaining users can be handled by a quick and easy bit of jQuery.<span id="more-422"></span></p>
<h3>For the (better) browsers&#8230;</h3>
<p>It&#8217;s easy to add corners to your design in most browsers. In a previous post, I talked about the different ways to apply CSS corners within your design. Here&#8217;s what I used for this particular client.</p>
<div id="the-css">
<pre>.corners {
	-moz-border-radius: 12px;
	-webkit-border-radius: 12px;
}
.noTL {
	-moz-border-radius-topleft: 0;
	-webkit-border-top-left-radius: 0;
}
.noTR {
	-moz-border-radius-topright: 0;
	-webkit-border-top-right-radius: 0;
}
.noBL {
	-moz-border-radius-bottomleft: 0;
	-webkit-border-bottom-left-radius: 0;
}
.noBR {
	-moz-border-radius-bottomright: 0;
	-webkit-border-bottom-right-radius: 0;
}</pre>
</div>
<p>This made it extremely easy to add corners to the elements in my design. In most cases, I could simply add <code>&lt;div class=&quot;myDivClass <strong>corners</strong>&quot;/&gt;</code>, and the CSS does the rest. If I don&#8217;t want a rounded edge on a particular corner, I can just add <code>noTR</code>, <code>noBL</code>, etc. to my class list. Easy.</p>
<h3>For the other (not-so-better) browser&#8230;</h3>
<p><strong>Disclaimer:</strong> this really doesn&#8217;t do anything entirely too amazing. It&#8217;s not auto-magically generating corner images, and it&#8217;s not inserting a ton of HTML to simulate corner images (I just hate when scripts do that). This is a script I have been using for a while to add corners for IE users; basically, it builds a custom image path for each style of widget in your design marked with the <code>corners</code> CSS class. For each corners widget that my script finds, it will trace up through your HTML until it finds a parent element with a <code>background-color</code>. It then creates four <code>&lt;div/&gt;</code> tags inside your widget and positions them at the outer corners of the widget. The background-image for these <code>&lt;div/&gt;</code> tags is set to something like <strong>corners-12-ffffff.png</strong> or <strong>corners-12-ffaa10-border</strong> (if your widget has a border-width associated with it). The <code>12</code> is the radius of your corner, and <code>ffffff</code> is the background color that appears behind your widget. You&#8217;ll have to create the images yourself (and put them in the right place), but my script will handle inserting the HTML and CSS in the right place. If you create the images <a href="http://www.kyleschaeffer.com/best-practices/reusable-transparent-css-rounded-corners/">a little like this</a>, then you&#8217;ll find that your IE corners will be in place in no time at all.</p>
<p>It&#8217;s certainly not ground-breaking stuff, but it makes it very easy to reduce the overhead in your design for most users. In addition, the script is fairly small, and you&#8217;ll find it&#8217;s really not much overhead for IE users as well. Here&#8217;s how to add it to your site:</p>
<ol>
<li>You&#8217;ll need <a href="http://jquery.com/">jQuery 1.3.2</a> or later linked to your page</li>
<li>Add the <a href="#the-css">CSS (above)</a> to your style sheet. This takes care of everyone except for IE.</li>
<li>Create a new JavaScript file with the following contents:
<pre>/*******************************************

	IE Corner Inserts v1.0

	by Kyle Schaeffer

http://www.kyleschaeffer.com

	* requires jQuery 1.3.2 or later

*******************************************/

// change this path to match the path to your corner image files
var cornerImagePathPrefix = '/designImages/';

// default file extension for corner images is PNG
var cornerImageFileExtension = '.png';

// default corner radius
var cornerRadius = '12';

$(document).ready(function(){
	$('.corners').each(function(i){
		var parentDiv = $(this).parent();
		var cornerColor = null;

		// find parent background color (trace up through DOM)
		while(cornerColor == null &amp;&amp; parentDiv != null){
			if($(parentDiv).css('background-color') != 'transparent'){
				cornerColor = $(parentDiv).css('background-color');
				cornerColor = cornerColor.substr(1);
			}
			else if($(parentDiv).hasClass('bodyWrapper')){
				cornerColor = '6f98ae';
			}
			else{
				parentDiv = $(parentDiv).parent().get(0);
			}
		}

		// apply corner &lt;div/&gt; tags to elements
		if(cornerColor != null){
			// find border offsets
			var offsetTop = parseInt($(this).css('border-top-width')) || 0;
			var offsetRight = parseInt($(this).css('border-right-width')) || 0;
			var offsetBottom = parseInt($(this).css('border-bottom-width')) || 0;
			var offsetLeft = parseInt($(this).css('border-left-width')) || 0;

			// add &quot;-border&quot; to any image path (for border-only corners)
			var borderImageText = '';
			if(offsetTop &gt; 0 &amp;&amp; offsetRight &gt; 0 &amp;&amp; offsetBottom &gt; 0 &amp;&amp; offsetLeft &gt; 0){
				borderImageText = '-border';
			}

			// change color values like &quot;#fff&quot; to &quot;#ffffff&quot;
			if(cornerColor.length == 3){
				cornerColor += cornerColor;
			}

			// set position to relative (if not already set)
			if($(this).css('position') != 'absolute' &amp;&amp; $(this).css('position') != 'relative'){
				$(this).css('position','relative');
			}

			// corner image filename
			var cornerImage = 'corners-' + cornerRadius + '-' + cornerColor + borderImageText + cornerImageFileExtension;

			// add corners
			if(!$(this).hasClass('noTL')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') top left no-repeat;&quot;/&gt;');
				$(cornerDiv).css('top',(offsetTop * -1) + 'px');
				$(cornerDiv).css('left',(offsetLeft * -1) + 'px');
				$(this).append(cornerDiv);
			}
			if(!$(this).hasClass('noTR')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') top right no-repeat;&quot;/&gt;');
				$(cornerDiv).css('top',(offsetTop * -1) + 'px');
				$(cornerDiv).css('right',(offsetRight * -1) + 'px');
				$(this).append(cornerDiv);
			}
			if(!$(this).hasClass('noBL')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') bottom left no-repeat;&quot;/&gt;');
				$(cornerDiv).css('bottom',(offsetBottom * -1) + 'px');
				$(cornerDiv).css('left',(offsetLeft * -1) + 'px');
				$(this).append(cornerDiv);
			}
			if(!$(this).hasClass('noBR')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') bottom right no-repeat;&quot;/&gt;');
				$(cornerDiv).css('bottom',(offsetBottom * -1) + 'px');
				$(cornerDiv).css('right',(offsetRight * -1) + 'px');
				$(this).append(cornerDiv);
			}
		}
	});
});

String.prototype.endsWith = function(str){
	return(this.match(str+&quot;$&quot;)==str);
}</pre>
</li>
<li>Take a look at the configuration variables near the top of the script and update if needed</li>
<li>Link to your new JS file, but make sure only IE users are loading the file:
<pre>&lt;!--[if lte IE 8]&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;/path/to/IE-Corner-Inserts.js&quot;&gt;&lt;/script&gt;
&lt;![endif]--&gt;</pre>
</li>
<li>Create your corner images and place them in the correct path on your web server. I recently made available <a href="http://www.kyleschaeffer.com/best-practices/reusable-transparent-css-rounded-corners/">a corner images Photoshop template</a> if you need help getting started.</li>
</ol>
<p>That&#8217;s it! If all goes well, you should hopefully see image-based rounded corners in Internet Explorer, as well as the more simplistic CSS-powered corners in all other browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/tutorials/ie-corner-inserts-via-jquery/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>A Simple jQuery Tabs Template</title>
		<link>http://kyleschaeffer.com/web-controls/simple-jquery-tabs-template/</link>
		<comments>http://kyleschaeffer.com/web-controls/simple-jquery-tabs-template/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 14:47:28 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Web Controls]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tabs]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=348</guid>
		<description><![CDATA[I love jQuery; I use it all the time. I also love the great UI controls that come with the jQuery UI library. Unfortunately, I&#8217;ve found that a lot of these controls can be a little heavy in terms of required JS/CSS files that your clients will have to download in order to use these [...]]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://jquery.com/">jQuery</a>; I use it all the time. I also love the great UI controls that come with the <a href="http://jqueryui.com/">jQuery UI</a> library. Unfortunately, I&#8217;ve found that a lot of these controls can be a little heavy in terms of required JS/CSS files that your clients will have to download in order to use these controls. Being the minimalist that I am, I really want to drop a small amount of CSS and HTML into my site and quickly get myself up and running with a tab structure that&#8217;s both flexible and accessible.<span id="more-348"></span></p>
<h3>Adding jQuery is Easy</h3>
<p>You&#8217;ll need to include a few JavaScript libraries in order to use jQuery tabs at all. These libraries can be somewhat cumbersome for users on slower connections to download, and it&#8217;s definitely the major disadvantage of using a library like jQuery to add this sort of functionality to your site. The best things we can do in this case is try to minimize the effect of serving this JS library to our clients. First of all, I would recommend always using the &#8220;minified&#8221; version of the jQuery script. It&#8217;s much smaller in size than the standard version, which obviously will reduce the amount of time needed to load your site when users first visit it. The only difference between the minified and the standard library is that the good folks at jQuery have removed all sorts of characters in the document, which makes it less readable, but makes the file size much smaller. If you want to delve into the depths of the jQuery library, you can download the standard version and take a gander offline, but don&#8217;t force your users to download the full version if you don&#8217;t have to.</p>
<p>Additionally, Google (<a href="http://code.google.com/apis/ajaxlibs/documentation/#jquery">here</a>) and Microsoft (<a href="http://www.asp.net/ajax/CDN/">here</a>) have both set up distribution networks to serve these libraries to your users. Don&#8217;t waste bandwidth and your clients&#8217; time by forcing users to download these libraries from your servers! Chances are, Google/Microsoft have the resources to serve these files to you users faster and more reliably than you can, so please utilize these free services. Additionally, users have a much greater chance of already having a cached version of these files when you used the shared location. Sweet!</p>
<p>Add the library references to your <code>&lt;head/&gt;</code> to get started.</p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://jqueryui.com/latest/ui/ui.tabs.js&quot;&gt;&lt;/script&gt;</pre>
<h3>The Tabs Markup</h3>
<p>What&#8217;s so wonderfully beautiful about jQuery tabs is the simplicity of the HTML. Even more, users who aren&#8217;t using JavaScript will visit your site and see a perfectly formatted and functioning page. Use this as a template for your tabs HTML:</p>
<pre>&lt;div class=&quot;ui-tabs&quot;&gt;
	&lt;ul class=&quot;ui-tabs-nav&quot;&gt;
		&lt;li&gt;&lt;a href=&quot;#tabs-1&quot;&gt;Tab One&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tabs-2&quot;&gt;Tab Two&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tabs-3&quot;&gt;Tab Three&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div id=&quot;tabs-1&quot; class=&quot;ui-tabs-panel&quot;&gt;
		&lt;p&gt;Content one.&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id=&quot;tabs-2&quot; class=&quot;ui-tabs-panel&quot;&gt;
		&lt;p&gt;Content two.&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id=&quot;tabs-3&quot; class=&quot;ui-tabs-panel&quot;&gt;
		&lt;p&gt;Content three.&lt;/p&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<h3>Add Some Style</h3>
<p>This is where my template really starts to differ from jQuery&#8217;s version. The CSS jQuery would have you use is not simple enough for me, so I created my own version of the CSS that will give you a very basic frame onto which you can apply your own design. Here&#8217;s what I like to start with:</p>
<pre>.ui-tabs {
	zoom: 1;
}
.ui-tabs .ui-tabs-nav {
	list-style: none;
	position: relative;
	padding: 0;
	margin: 0;
}
.ui-tabs .ui-tabs-nav li {
	position: relative;
	float: left;
	margin: 0 3px -2px 0;
	padding: 0;
}
.ui-tabs .ui-tabs-nav li a {
	display: block;
	padding: 10px 20px;
	background: #f0f0f0;
	border: 2px #ccc solid;
	border-bottom-color: #ccc;
	outline: none;
}
.ui-tabs .ui-tabs-nav li.ui-tabs-selected a {
	padding: 10px 20px 12px 20px;
	background: #fff;
	border-bottom-style: none;
}
.ui-tabs .ui-tabs-nav li.ui-tabs-selected a,
.ui-tabs .ui-tabs-nav li.ui-state-disabled a,
.ui-tabs .ui-tabs-nav li.ui-state-processing a {
	cursor: default;
}
.ui-tabs .ui-tabs-nav li a,
.ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a {
	cursor: pointer;
}
.ui-tabs .ui-tabs-panel {
	display: block;
	clear: both;
	border: 2px #ccc solid;
	padding: 10px;
}
.ui-tabs .ui-tabs-hide {
	display: none;
}</pre>
<h3>Now Make it Do Something</h3>
<p>Now that you have your tabs there, you&#8217;ll have to initialize them with a simple jQuery statement in order for them to work. Just add this line of JavaScript anywhere on your page.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function(){
		$(&quot;.ui-tabs&quot;).tabs();
	});
&lt;/script&gt;</pre>
<h3>The Result</h3>
<p>Once you&#8217;ve added each of these elements to your page, you should get a very simple tab structure that awaits your styling genius. Just modify the CSS to apply your own design!</p>
<div class="ui-tabs">
<ul class="ui-tabs-nav">
<li><a href="#tabs-1">Tab One</a></li>
<li><a href="#tabs-2">Tab Two</a></li>
<li><a href="#tabs-3">Tab Three</a></li>
</ul>
<div id="tabs-1" class="ui-tabs-panel">
<p>Content one.</p>
</div>
<div id="tabs-2" class="ui-tabs-panel">
<p>Content two.</p>
</div>
<div id="tabs-3" class="ui-tabs-panel">
<p>Content three.</p>
</div>
</div>
<p><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script><script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.tabs.js"></script><script type="text/javascript">$(document).ready(function(){$(".ui-tabs").tabs();});</script><br />
<style type="text/css">#content .ui-tabs { zoom: 1; }
#content .ui-tabs .ui-tabs-nav { list-style: none; position: relative; padding: 0; margin: 0; }
#content .ui-tabs .ui-tabs-nav li { list-style: none; position: relative; float: left; margin: 0 3px -2px 0; padding: 0; }
#content .ui-tabs .ui-tabs-nav li a { display: block; padding: 10px 20px; background: #f0f0f0; border: 2px #ccc solid; border-bottom-color: #ccc; outline: none; }
#content .ui-tabs .ui-tabs-nav li.ui-tabs-selected a { padding: 10px 20px 12px 20px; background: #fff; border-bottom-style: none; }
#content .ui-tabs .ui-tabs-nav li.ui-tabs-selected a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-state-processing a { cursor: default; }
#content .ui-tabs .ui-tabs-nav li a, .ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a { cursor: pointer; }
#content .ui-tabs .ui-tabs-panel { display: block; clear: both; border: 2px #ccc solid; padding: 10px; }
#content .ui-tabs .ui-tabs-hide { display: none; }</style>
<p>Now you&#8217;ve got it. Good luck, and happy styling.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/web-controls/simple-jquery-tabs-template/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create a DHTML Tab Strip</title>
		<link>http://kyleschaeffer.com/tutorials/create-a-dhtml-tab-strip/</link>
		<comments>http://kyleschaeffer.com/tutorials/create-a-dhtml-tab-strip/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 18:18:23 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Controls]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tabs]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=107</guid>
		<description><![CDATA[Tab strips are commonplace throughout the web, and they&#8217;re utilized in a wide variety of ways, such as in site navigation or form wizards. Organizing links in a tabbed format can add quite a bit of style and functionality to your site, as many visitors are already familiar and comfortable with using tabs on other [...]]]></description>
			<content:encoded><![CDATA[<p>Tab strips are commonplace throughout the web, and they&#8217;re utilized in a wide variety of ways, such as in site navigation or form wizards.  Organizing links in a tabbed format can add quite a bit of style and functionality to your site, as many visitors are already familiar and comfortable with using tabs on other websites and even on other platforms such as their operating system.  This tutorial shows you how to create a simple DHTML tab strip using HTML, CSS, and a small bit of JavaScript.<span id="more-107"></span></p>
<p>When I use the term &#8220;DHTML,&#8221; I am referring to &#8220;Dynamic HTML.&#8221;  This is an endearing term that many web designers use to describe the fusion of HTML with other web technologies, such as JavaScript and CSS.  By using various technologies in tandem, we can create dynamic controls that allow website visitors to interact with content directly on the page without the need to refresh the site with every subsequent click.</p>
<h3>The HTML</h3>
<p>As you will soon see, the tab strip is a prime example of a DHTML control.  Before we delve into every aspect of the tab strip, let&#8217;s first start with the HTML:</p>
<pre>&lt;div class=&quot;tabStrip&quot;&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;javascript:openTab(1);&quot; class=&quot;tabLinkActive&quot; id=&quot;tabLink1&quot;&gt;TabOne&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;javascript:openTab(2);&quot; class=&quot;tabLink&quot; id=&quot;tabLink2&quot;&gt;TabTwo&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;javascript:openTab(3);&quot; class=&quot;tabLink&quot; id=&quot;tabLink3&quot;&gt;TabThree&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;tabContentActive&quot; id=&quot;tabContent1&quot;&gt;
	This is sample tab content (1).
&lt;/div&gt;
&lt;div class=&quot;tabContent&quot; id=&quot;tabContent2&quot;&gt;
	This is sample tab content (2).
&lt;/div&gt;
&lt;div class=&quot;tabContent&quot; id=&quot;tabContent3&quot;&gt;
	This is sample tab content (3).
&lt;/div&gt;</pre>
<p>The HTML is relatively simple. We are using an unordered list (<code>&lt;ul/&gt;</code>) for our tabs, and we are using <code>&lt;div/&gt;</code> tags for our tab content. As you can see, I am giving a unique <code>id</code> attribute to each tab link and to each tab content <code>&lt;div/&gt;</code>.  This is important, as we&#8217;ll need unique <code>id</code>&#8216;s in order to access these elements with JavaScript.</p>
<h3>The JavaScript</h3>
<p>We are using only one small JavaScript function for the tab control.  Here is the code:</p>
<pre>&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
	var activeTab = 1;
	function openTab(tabId) {
		// reset old tab and content
		document.getElementById(&quot;tabLink&quot;+activeTab).className = &quot;tabLink&quot;;
		document.getElementById(&quot;tabContent&quot;+activeTab).className = &quot;tabContent&quot;;
		// set new tab and content
		document.getElementById(&quot;tabLink&quot;+tabId).className = &quot;tabLinkActive&quot;;
		document.getElementById(&quot;tabContent&quot;+tabId).className = &quot;tabContentActive&quot;;
		activeTab = tabId;
	}
&lt;/script&gt;</pre>
<h3>The CSS:</h3>
<p>This CSS is a very basic example of what you can do to style your tabs. You can add colors, gradients, and background images to give the control even more design flare.</p>
<pre>.tabStrip ul {
	margin: 0;
	padding: 0;
	list-style-type: none;
}
.tabStrip li {
	margin: 0 2px 0 0;
	list-style-type: none;
	float: left;
}
.tabLink {
	display: block;
	text-decoration: none;
	padding: 5px;
	background: #e8e8e8;
	border: #dadada solid;
	border-width: 1px 1px 0 1px;
	color: #8a8a8a;
}
.tabLinkActive {
	display: block;
	text-decoration: none;
	padding: 5px;
	background: #e0e0e0;
	border: #c0c0c0 solid;
	border-width: 1px 1px 0 1px;
	color: #0066ff;
}
.tabContent {
	display: none;
}
.tabContentActive {
	display: block;
	clear: both;
	background: #f0f0f0;
	border: 1px #dedede solid;
	padding: 10px;
}</pre>
<h3>The Result:</h3>
<p>In true DHTML fashion, we have combined HTML, JavaScript, and CSS to create a fully dynamic user control that can appear anywhere on the web. I have taken the fundamentals learned in this tutorial and have created a more visually appealing example of this code.  Click on the image below to see the demo.</p>
<p><a href="http://www.kyleschaeffer.com/tabstrip/"><img src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2008/11/tabs.jpg" alt="Tab Strip Demo" /></a></p>
<p>Note that the demo also utilizes Karate Corners to create rounded edges on the tabs.  <a href="http://www.kyleschaeffer.com/tutorials/karate-corners-easy-rounded-corners-xhtml-no-script/">Learn more about Karate corners here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/tutorials/create-a-dhtml-tab-strip/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
