<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>Internaut Design -  You Dream It, We Build It!  </title>
  <meta name="generator" content="Mephisto" />
  <script src="/javascripts/prototype.js" type="text/javascript"></script>
  <script src="/javascripts/code_highlighter.js" type="text/javascript"></script>
  <script src="/javascripts/javascript.js" type="text/javascript"></script> 
  <script src="/javascripts/css.js" type="text/javascript"></script>
  <script src="/javascripts/html.js" type="text/javascript"></script>
  <script src="/javascripts/ruby.js" type="text/javascript"></script>
  <script src="/javascripts/code_hover.js" type="text/javascript"></script>
  <link href="/stylesheets/main.css" rel="stylesheet" type="text/css" />
  <link href="/feed/atom.xml" rel="alternate" type="application/atom+xml" />
    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
    </script>
    <script type="text/javascript">
    _uacct = "UA-927732-2";
    urchinTracker();
    </script>

</head>
<body>
<div id="header"><a href="http://internautdesign.com/" title="Internaut Design Homepage" class="logo"><img src="http://internautdesign.com/images/internaut_logo.png"/></a>
      <p class="description">&mdash;You Dream It, We Build It!<br /><br /></p>
<a href="http://internautdesign.com/">A San Francisco based Ruby on Rails Consultancy.</a>
      <hr />
    </div>

  <div id="wrap">
    <div id="content">
      
<div class="entry entry-162">
	<div class="entrytitle">
		<h2><a href="/2007/11/30/zebra-striping-with-prototype">unobtrusive zebra striping with prototype.js</a></h2> 
		<div class="entrymeta">
			<p><span class="date">November 30th, 2007</span> <br />
			Posted by <a href="">David Lowenfels</a><br />
		Filed in: <br />

  <a href="/tags/prototype.js">prototype.js</a>



			  
			
			</p>
		</div>
	</div>
	<div class="entrybody">
	  
		  <p>I just cooked up some flexible zebra striping for prototype.
I call it
<em>...drumroll please&#8230;</em>
         ProtoStripe!</p>


	<p><em>badum-ching!</em> ;)</p>


<pre>
<code class="javascript">
// protostripe.js

Event.observe( window, 'DOMContentLoaded', function() {

  $$('.striped').each( function(e) {
    Selector.findChildElements(e, ['tr','li']).each( function(e, idx) {
      e.addClassName( idx % 2 == 1 ? 'odd' : 'even');
    });    
  });

});
</code>
</pre>

	<p>Just include it in your <span class="caps">HTML</span> header, and any tables or lists with class=&#8221;striped&#8221; will have their appropriate children decorated with &#8220;odd&#8221; and &#8220;even&#8221; <span class="caps">CSS</span> classes.
Unobtrusive JavaScript rocks! :)</p>
		
		
	</div>
	
</div>








  <span style='font-size: 0.5em'><a title='actionmailer' href='/tags/actionmailer'>actionmailer</a></span>

  <span style='font-size: 0.5em'><a title='ActionView' href='/tags/ActionView'>ActionView</a></span>

  <span style='font-size: 0.5em'><a title='ActiveRecord' href='/tags/ActiveRecord'>ActiveRecord</a></span>

  <span style='font-size: 0.5em'><a title='activesupport' href='/tags/activesupport'>activesupport</a></span>

  <span style='font-size: 0.5em'><a title='agile' href='/tags/agile'>agile</a></span>

  <span style='font-size: 0.5em'><a title='ajax' href='/tags/ajax'>ajax</a></span>

  <span style='font-size: 0.5em'><a title='alphadecimal' href='/tags/alphadecimal'>alphadecimal</a></span>

  <span style='font-size: 0.5em'><a title='audio' href='/tags/audio'>audio</a></span>

  <span style='font-size: 0.5em'><a title='autotest' href='/tags/autotest'>autotest</a></span>

  <span style='font-size: 0.5em'><a title='BDD' href='/tags/BDD'>BDD</a></span>

  <span style='font-size: 0.5em'><a title='blocks' href='/tags/blocks'>blocks</a></span>

  <span style='font-size: 0.5em'><a title='capistrano ssh ruby' href='/tags/capistrano ssh ruby'>capistrano ssh ruby</a></span>

  <span style='font-size: 0.5em'><a title='console' href='/tags/console'>console</a></span>

  <span style='font-size: 0.5em'><a title='controller' href='/tags/controller'>controller</a></span>

  <span style='font-size: 0.5em'><a title='css' href='/tags/css'>css</a></span>

  <span style='font-size: 0.5em'><a title='dashboard widget' href='/tags/dashboard widget'>dashboard widget</a></span>

  <span style='font-size: 0.5em'><a title='delegate' href='/tags/delegate'>delegate</a></span>

  <span style='font-size: 0.5em'><a title='dog puppy naming name' href='/tags/dog puppy naming name'>dog puppy naming name</a></span>

  <span style='font-size: 0.5em'><a title='DRM' href='/tags/DRM'>DRM</a></span>

  <span style='font-size: 0.5em'><a title='email obfuscation' href='/tags/email obfuscation'>email obfuscation</a></span>

  <span style='font-size: 0.5em'><a title='exceptions' href='/tags/exceptions'>exceptions</a></span>

  <span style='font-size: 0.5em'><a title='factories' href='/tags/factories'>factories</a></span>

  <span style='font-size: 0.5em'><a title='factories-and-workers' href='/tags/factories-and-workers'>factories-and-workers</a></span>

  <span style='font-size: 0.5em'><a title='factory pattern' href='/tags/factory pattern'>factory pattern</a></span>

  <span style='font-size: 0.5em'><a title='filemerge' href='/tags/filemerge'>filemerge</a></span>

  <span style='font-size: 0.5em'><a title='find and replace' href='/tags/find and replace'>find and replace</a></span>

  <span style='font-size: 0.5em'><a title='finder' href='/tags/finder'>finder</a></span>

  <span style='font-size: 0.5em'><a title='fink' href='/tags/fink'>fink</a></span>

  <span style='font-size: 1.00em'><a title='fixtures' href='/tags/fixtures'>fixtures</a></span>

  <span style='font-size: 0.5em'><a title='fun' href='/tags/fun'>fun</a></span>

  <span style='font-size: 0.5em'><a title='functional testing' href='/tags/functional testing'>functional testing</a></span>

  <span style='font-size: 0.5em'><a title='gem' href='/tags/gem'>gem</a></span>

  <span style='font-size: 0.80em'><a title='git' href='/tags/git'>git</a></span>

  <span style='font-size: 0.5em'><a title='google maps' href='/tags/google maps'>google maps</a></span>

  <span style='font-size: 0.5em'><a title='haml' href='/tags/haml'>haml</a></span>

  <span style='font-size: 0.5em'><a title='helper' href='/tags/helper'>helper</a></span>

  <span style='font-size: 0.5em'><a title='helpers' href='/tags/helpers'>helpers</a></span>

  <span style='font-size: 0.5em'><a title='imagemagick' href='/tags/imagemagick'>imagemagick</a></span>

  <span style='font-size: 0.5em'><a title='Intertrust' href='/tags/Intertrust'>Intertrust</a></span>

  <span style='font-size: 0.5em'><a title='irb' href='/tags/irb'>irb</a></span>

  <span style='font-size: 0.5em'><a title='javascript' href='/tags/javascript'>javascript</a></span>

  <span style='font-size: 0.5em'><a title='jquery' href='/tags/jquery'>jquery</a></span>

  <span style='font-size: 0.5em'><a title='jrails' href='/tags/jrails'>jrails</a></span>

  <span style='font-size: 0.5em'><a title='logo' href='/tags/logo'>logo</a></span>

  <span style='font-size: 0.5em'><a title='macro' href='/tags/macro'>macro</a></span>

  <span style='font-size: 0.5em'><a title='math' href='/tags/math'>math</a></span>

  <span style='font-size: 0.5em'><a title='meetup' href='/tags/meetup'>meetup</a></span>

  <span style='font-size: 0.5em'><a title='model' href='/tags/model'>model</a></span>

  <span style='font-size: 0.5em'><a title='openssl' href='/tags/openssl'>openssl</a></span>

  <span style='font-size: 1.40em'><a title='OS X' href='/tags/OS X'>OS X</a></span>

  <span style='font-size: 0.5em'><a title='patch' href='/tags/patch'>patch</a></span>

  <span style='font-size: 0.5em'><a title='Pioneer Electronics' href='/tags/Pioneer Electronics'>Pioneer Electronics</a></span>

  <span style='font-size: 1.00em'><a title='plugin' href='/tags/plugin'>plugin</a></span>

  <span style='font-size: 0.5em'><a title='polymorphism' href='/tags/polymorphism'>polymorphism</a></span>

  <span style='font-size: 0.5em'><a title='project management' href='/tags/project management'>project management</a></span>

  <span style='font-size: 0.5em'><a title='prototype.js' href='/tags/prototype.js'>prototype.js</a></span>

  <span style='font-size: 2em'><a title='rails' href='/tags/rails'>rails</a></span>

  <span style='font-size: 0.5em'><a title='rails gotcha' href='/tags/rails gotcha'>rails gotcha</a></span>

  <span style='font-size: 0.5em'><a title='rails,patch,validations' href='/tags/rails,patch,validations'>rails,patch,validations</a></span>

  <span style='font-size: 0.5em'><a title='railsconf' href='/tags/railsconf'>railsconf</a></span>

  <span style='font-size: 0.5em'><a title='rake' href='/tags/rake'>rake</a></span>

  <span style='font-size: 0.5em'><a title='rmagick' href='/tags/rmagick'>rmagick</a></span>

  <span style='font-size: 0.60em'><a title='RSA encryption' href='/tags/RSA encryption'>RSA encryption</a></span>

  <span style='font-size: 2em'><a title='ruby' href='/tags/ruby'>ruby</a></span>

  <span style='font-size: 0.5em'><a title='ruby on rails' href='/tags/ruby on rails'>ruby on rails</a></span>

  <span style='font-size: 0.5em'><a title='script' href='/tags/script'>script</a></span>

  <span style='font-size: 0.60em'><a title='scrum' href='/tags/scrum'>scrum</a></span>

  <span style='font-size: 0.5em'><a title='scrum lessons rails' href='/tags/scrum lessons rails'>scrum lessons rails</a></span>

  <span style='font-size: 0.5em'><a title='scrumninja' href='/tags/scrumninja'>scrumninja</a></span>

  <span style='font-size: 2.00em'><a title='shoulda' href='/tags/shoulda'>shoulda</a></span>

  <span style='font-size: 0.60em'><a title='subversion' href='/tags/subversion'>subversion</a></span>

  <span style='font-size: 0.5em'><a title='SyncTV' href='/tags/SyncTV'>SyncTV</a></span>

  <span style='font-size: 0.5em'><a title='TDD' href='/tags/TDD'>TDD</a></span>

  <span style='font-size: 2em'><a title='testing' href='/tags/testing'>testing</a></span>

  <span style='font-size: 1.00em'><a title='textmate' href='/tags/textmate'>textmate</a></span>

  <span style='font-size: 0.5em'><a title='tips' href='/tags/tips'>tips</a></span>

  <span style='font-size: 1.40em'><a title='tricks' href='/tags/tricks'>tricks</a></span>

  <span style='font-size: 0.5em'><a title='unique hashes' href='/tags/unique hashes'>unique hashes</a></span>

  <span style='font-size: 0.5em'><a title='unix shell' href='/tags/unix shell'>unix shell</a></span>

  <span style='font-size: 0.5em'><a title='validation' href='/tags/validation'>validation</a></span>

  <span style='font-size: 0.5em'><a title='view' href='/tags/view'>view</a></span>

  <span style='font-size: 0.60em'><a title='yaml' href='/tags/yaml'>yaml</a></span>

  <span style='font-size: 0.5em'><a title='zebra stripes' href='/tags/zebra stripes'>zebra stripes</a></span>



    </div>
    <div id="sidebar">
      <br/>
      <a href="http://scrumninja.com"><img style="border:none;width:200px" src="http://scrumninja.com/images/ScrumNinja.png"></img></a>

      <h2>Search</h2>
      <form method="get" id="sform" action="/search">
	  <input type="text" id="searchBox" value="" name="q" size="15" />
      </form>
      <h2>Tag Cloud</h2>
    
  <span style='font-size: 0.5em'><a title='actionmailer' href='/tags/actionmailer'>actionmailer</a></span>

  <span style='font-size: 0.5em'><a title='ActionView' href='/tags/ActionView'>ActionView</a></span>

  <span style='font-size: 0.5em'><a title='ActiveRecord' href='/tags/ActiveRecord'>ActiveRecord</a></span>

  <span style='font-size: 0.5em'><a title='activesupport' href='/tags/activesupport'>activesupport</a></span>

  <span style='font-size: 0.5em'><a title='agile' href='/tags/agile'>agile</a></span>

  <span style='font-size: 0.5em'><a title='ajax' href='/tags/ajax'>ajax</a></span>

  <span style='font-size: 0.5em'><a title='alphadecimal' href='/tags/alphadecimal'>alphadecimal</a></span>

  <span style='font-size: 0.5em'><a title='audio' href='/tags/audio'>audio</a></span>

  <span style='font-size: 0.5em'><a title='autotest' href='/tags/autotest'>autotest</a></span>

  <span style='font-size: 0.5em'><a title='BDD' href='/tags/BDD'>BDD</a></span>

  <span style='font-size: 0.5em'><a title='blocks' href='/tags/blocks'>blocks</a></span>

  <span style='font-size: 0.5em'><a title='capistrano ssh ruby' href='/tags/capistrano ssh ruby'>capistrano ssh ruby</a></span>

  <span style='font-size: 0.5em'><a title='console' href='/tags/console'>console</a></span>

  <span style='font-size: 0.5em'><a title='controller' href='/tags/controller'>controller</a></span>

  <span style='font-size: 0.5em'><a title='css' href='/tags/css'>css</a></span>

  <span style='font-size: 0.5em'><a title='dashboard widget' href='/tags/dashboard widget'>dashboard widget</a></span>

  <span style='font-size: 0.5em'><a title='delegate' href='/tags/delegate'>delegate</a></span>

  <span style='font-size: 0.5em'><a title='dog puppy naming name' href='/tags/dog puppy naming name'>dog puppy naming name</a></span>

  <span style='font-size: 0.5em'><a title='DRM' href='/tags/DRM'>DRM</a></span>

  <span style='font-size: 0.5em'><a title='email obfuscation' href='/tags/email obfuscation'>email obfuscation</a></span>

  <span style='font-size: 0.5em'><a title='exceptions' href='/tags/exceptions'>exceptions</a></span>

  <span style='font-size: 0.5em'><a title='factories' href='/tags/factories'>factories</a></span>

  <span style='font-size: 0.5em'><a title='factories-and-workers' href='/tags/factories-and-workers'>factories-and-workers</a></span>

  <span style='font-size: 0.5em'><a title='factory pattern' href='/tags/factory pattern'>factory pattern</a></span>

  <span style='font-size: 0.5em'><a title='filemerge' href='/tags/filemerge'>filemerge</a></span>

  <span style='font-size: 0.5em'><a title='find and replace' href='/tags/find and replace'>find and replace</a></span>

  <span style='font-size: 0.5em'><a title='finder' href='/tags/finder'>finder</a></span>

  <span style='font-size: 0.5em'><a title='fink' href='/tags/fink'>fink</a></span>

  <span style='font-size: 1.00em'><a title='fixtures' href='/tags/fixtures'>fixtures</a></span>

  <span style='font-size: 0.5em'><a title='fun' href='/tags/fun'>fun</a></span>

  <span style='font-size: 0.5em'><a title='functional testing' href='/tags/functional testing'>functional testing</a></span>

  <span style='font-size: 0.5em'><a title='gem' href='/tags/gem'>gem</a></span>

  <span style='font-size: 0.80em'><a title='git' href='/tags/git'>git</a></span>

  <span style='font-size: 0.5em'><a title='google maps' href='/tags/google maps'>google maps</a></span>

  <span style='font-size: 0.5em'><a title='haml' href='/tags/haml'>haml</a></span>

  <span style='font-size: 0.5em'><a title='helper' href='/tags/helper'>helper</a></span>

  <span style='font-size: 0.5em'><a title='helpers' href='/tags/helpers'>helpers</a></span>

  <span style='font-size: 0.5em'><a title='imagemagick' href='/tags/imagemagick'>imagemagick</a></span>

  <span style='font-size: 0.5em'><a title='Intertrust' href='/tags/Intertrust'>Intertrust</a></span>

  <span style='font-size: 0.5em'><a title='irb' href='/tags/irb'>irb</a></span>

  <span style='font-size: 0.5em'><a title='javascript' href='/tags/javascript'>javascript</a></span>

  <span style='font-size: 0.5em'><a title='jquery' href='/tags/jquery'>jquery</a></span>

  <span style='font-size: 0.5em'><a title='jrails' href='/tags/jrails'>jrails</a></span>

  <span style='font-size: 0.5em'><a title='logo' href='/tags/logo'>logo</a></span>

  <span style='font-size: 0.5em'><a title='macro' href='/tags/macro'>macro</a></span>

  <span style='font-size: 0.5em'><a title='math' href='/tags/math'>math</a></span>

  <span style='font-size: 0.5em'><a title='meetup' href='/tags/meetup'>meetup</a></span>

  <span style='font-size: 0.5em'><a title='model' href='/tags/model'>model</a></span>

  <span style='font-size: 0.5em'><a title='openssl' href='/tags/openssl'>openssl</a></span>

  <span style='font-size: 1.40em'><a title='OS X' href='/tags/OS X'>OS X</a></span>

  <span style='font-size: 0.5em'><a title='patch' href='/tags/patch'>patch</a></span>

  <span style='font-size: 0.5em'><a title='Pioneer Electronics' href='/tags/Pioneer Electronics'>Pioneer Electronics</a></span>

  <span style='font-size: 1.00em'><a title='plugin' href='/tags/plugin'>plugin</a></span>

  <span style='font-size: 0.5em'><a title='polymorphism' href='/tags/polymorphism'>polymorphism</a></span>

  <span style='font-size: 0.5em'><a title='project management' href='/tags/project management'>project management</a></span>

  <span style='font-size: 0.5em'><a title='prototype.js' href='/tags/prototype.js'>prototype.js</a></span>

  <span style='font-size: 2em'><a title='rails' href='/tags/rails'>rails</a></span>

  <span style='font-size: 0.5em'><a title='rails gotcha' href='/tags/rails gotcha'>rails gotcha</a></span>

  <span style='font-size: 0.5em'><a title='rails,patch,validations' href='/tags/rails,patch,validations'>rails,patch,validations</a></span>

  <span style='font-size: 0.5em'><a title='railsconf' href='/tags/railsconf'>railsconf</a></span>

  <span style='font-size: 0.5em'><a title='rake' href='/tags/rake'>rake</a></span>

  <span style='font-size: 0.5em'><a title='rmagick' href='/tags/rmagick'>rmagick</a></span>

  <span style='font-size: 0.60em'><a title='RSA encryption' href='/tags/RSA encryption'>RSA encryption</a></span>

  <span style='font-size: 2em'><a title='ruby' href='/tags/ruby'>ruby</a></span>

  <span style='font-size: 0.5em'><a title='ruby on rails' href='/tags/ruby on rails'>ruby on rails</a></span>

  <span style='font-size: 0.5em'><a title='script' href='/tags/script'>script</a></span>

  <span style='font-size: 0.60em'><a title='scrum' href='/tags/scrum'>scrum</a></span>

  <span style='font-size: 0.5em'><a title='scrum lessons rails' href='/tags/scrum lessons rails'>scrum lessons rails</a></span>

  <span style='font-size: 0.5em'><a title='scrumninja' href='/tags/scrumninja'>scrumninja</a></span>

  <span style='font-size: 2.00em'><a title='shoulda' href='/tags/shoulda'>shoulda</a></span>

  <span style='font-size: 0.60em'><a title='subversion' href='/tags/subversion'>subversion</a></span>

  <span style='font-size: 0.5em'><a title='SyncTV' href='/tags/SyncTV'>SyncTV</a></span>

  <span style='font-size: 0.5em'><a title='TDD' href='/tags/TDD'>TDD</a></span>

  <span style='font-size: 2em'><a title='testing' href='/tags/testing'>testing</a></span>

  <span style='font-size: 1.00em'><a title='textmate' href='/tags/textmate'>textmate</a></span>

  <span style='font-size: 0.5em'><a title='tips' href='/tags/tips'>tips</a></span>

  <span style='font-size: 1.40em'><a title='tricks' href='/tags/tricks'>tricks</a></span>

  <span style='font-size: 0.5em'><a title='unique hashes' href='/tags/unique hashes'>unique hashes</a></span>

  <span style='font-size: 0.5em'><a title='unix shell' href='/tags/unix shell'>unix shell</a></span>

  <span style='font-size: 0.5em'><a title='validation' href='/tags/validation'>validation</a></span>

  <span style='font-size: 0.5em'><a title='view' href='/tags/view'>view</a></span>

  <span style='font-size: 0.60em'><a title='yaml' href='/tags/yaml'>yaml</a></span>

  <span style='font-size: 0.5em'><a title='zebra stripes' href='/tags/zebra stripes'>zebra stripes</a></span>



    <h2>Blog Roll</h2>
    <ul>
        <li><a href="http://errtheblog.com">Err the Blog</a></li>
        <li><a href="http://rails.raaum.org/index.html">Raaum's Rails Reader</a></li>
        <li><a href="http://blog.mountaingoatsoftware.com/">Mike Cohn</a></li>
        <li><a href="http://www.pivotalblabs.com/">Pivotal Blabs</a></li>
        <li><a href="http://blog.scrumninja.com/">ScrumNinja</a></li>
    </ul>
    </div>

  </div>
  <div id="footer">Powered by <a href="http://mephistoblog.com/">Mephisto</a>.</div>
</body>
</html>
