<?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>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; YUI</title>
	<atom:link href="http://www.zachleat.com/web/tag/yui/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<lastBuildDate>Fri, 09 Dec 2011 21:53:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Faking Onload for Link Elements</title>
		<link>http://www.zachleat.com/web/load-css-dynamically/</link>
		<comments>http://www.zachleat.com/web/load-css-dynamically/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 01:50:24 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/?p=733</guid>
		<description><![CDATA[Updated 2011/09/27: Rejoice! This issue has now been fixed in Firefox. Or, I Am Dynamically Loaded CSS (and So Can You!) Dynamic resource loading is one of the keys to have a performance happy web application. There are generally three different criteria we must address when making a request: cross domain security policies, asynchronous/synchronous (will [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Updated 2011/09/27: Rejoice! This issue has now <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=185236">been fixed in Firefox</a>.</strong></p>
<hr/>
<p>Or, <strong>I Am Dynamically Loaded CSS (and So Can You!)</strong></p>
<p>Dynamic resource loading is one of the keys to have a performance happy web application.  There are generally three different criteria we must address when making a request: cross domain security policies, asynchronous/synchronous (will it block the host page while loading), and whether or not events are triggered when the request completes.</p>
<p>If the resource and host page are on the same domain, obviously <code>XMLHttpRequest</code> works the best.  We can control whether or not the resource is loaded asynchronously or synchronously, and we know exactly when it gets done.</p>
<p>If the resource and host page are on different domains (increasingly more common with CDN&#8217;s), our options narrow. Loading the JavaScript is a solved problem, just use the <code>onload</code> event on the <code>&lt;script&gt;</code> tag and you&#8217;re good to go (<code>onreadystatechange</code> for IE).  But CSS is more complicated.</p>
<table>
<thead>
<tr>
<th>Resource</th>
<th>Method</th>
<th>Option for (a)synchronous</th>
<th>Event</th>
</tr>
</thead>
<tbody>
<tr>
<td>JavaScript/CSS Same Domain</td>
<td><code>XMLHttpRequest</code></td>
<td>Both</td>
<td><code>onreadystatechange</code></td>
</tr>
<tr>
<td>JavaScript Different Domain</td>
<td><code>&lt;script&gt;</code></td>
<td>Synchronous (Asynchronous where <a href="https://developer.mozilla.org/en/html/element/script">async property</a> is supported)</td>
<td><code>onload</code><br />
<code>onreadystatechange</code> for IE</td>
</tr>
<tr>
<td>CSS  Different Domain</td>
<td><code>&lt;link&gt;</code></td>
<td>Asynchronous</td>
<td><em>What this blog post is about.</em></td>
</tr>
</tbody>
</table>
<h2>Existing Solutions</h2>
<p>In all of the library source code I evaluated, Internet Explorer didn&#8217;t cause any issues.  It fires both the <code>onload</code> and <code>onreadystatechange</code> events for <code>&lt;link&gt;</code> nodes.  Obviously this is ideal behavior, and IE got it right. But what about Firefox and Safari/Chrome?</p>
<h3>YUI 2.8.1 and 3.1.1</h3>
<p><a href="http://github.com/yui/yui3/blob/master/build/yui/get.js#L311">Original Source</a></p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">// FireFox does not support the onload event for link nodes, so there is
// no way to make the css requests synchronous. This means that the css 
// rules in multiple files could be applied out of order in this browser
// if a later request returns before an earlier one.  Safari too.
if ((ua.webkit || ua.gecko) &amp;&amp; q.type === &quot;css&quot;) {
    _next(id, url);
}</pre></div></div>

<p>I wouldn&#8217;t be surprised if the commit log there was from Bon Jovi; that code is living on a prayer.</p>
<h3>LazyLoad</h3>
<p><a href="http://github.com/rgrove/lazyload/blob/master/lazyload.js#L283">Original Source</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Gecko and WebKit don't support the onload event on link nodes. In</span>
<span style="color: #006600; font-style: italic;">// WebKit, we can poll for changes to document.styleSheets to figure out</span>
<span style="color: #006600; font-style: italic;">// when stylesheets have loaded, but in Gecko we just have to finish</span>
<span style="color: #006600; font-style: italic;">// after a brief delay and hope for the best.</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ua.<span style="color: #660066;">webkit</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    p.<span style="color: #660066;">urls</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> node.<span style="color: #660066;">href</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// resolve relative URLs (or polling won't work)</span>
    poll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    setTimeout<span style="color: #009900;">&#40;</span>_finish<span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span> <span style="color: #339933;">*</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Better, closer, warmer.  This includes a nice method for working with webkit browsers.  The poll method compares <code>document.styleSheets</code>, since Webkit has the nice option of only appending to the styleSheets object when the styleSheet has successfully loaded.</p>
<p>So we have working solutions for IE and Safari/Chrome. The only unsolved piece of the puzzle here is Firefox.</p>
<p><a href="http://wonko.com/post/how-to-prevent-yui-get-race-conditions">This post</a> from the same author as LazyLoad also describes another solution which involves modifying the source CSS and polling against it.  But that&#8217;s not really ideal. Can we do better?</p>
<h2>Solution</h2>
<p>Here&#8217;s what I came up with (using jQuery for brevity, note that this solution <strong>only fixes Firefox</strong>, and does not incorporate the above already solved solutions):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'css.php'</span><span style="color: #339933;">,</span>
    id <span style="color: #339933;">=</span> <span style="color: #3366CC;">'dynamicCss'</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;style/&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    id<span style="color: #339933;">:</span> id<span style="color: #339933;">,</span>
    type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'text/css'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'@import url('</span> <span style="color: #339933;">+</span> url <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> poll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> sheets <span style="color: #339933;">=</span> document.<span style="color: #660066;">styleSheets</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> k<span style="color: #339933;">=</span>sheets.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>k<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>sheets<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">ownerNode</span>.<span style="color: #660066;">id</span> <span style="color: #339933;">==</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                sheets<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">cssRules</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #006600; font-style: italic;">// If you made it here, success!</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'success!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Keep polling</span>
        window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span>poll<span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span>poll<span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3><a href="http://zachleat.com/javascript/loadcss/load.html">See this demo in action.</a> (Firefox only)</h3>
<p><br/><br />
<strong>Update</strong>: After much joy and celebration, I have discovered that an approach similar to the above was written by Oleg Slobodskoi in his <a href="http://plugins.jquery.com/files/jquery.xLazyLoader.js.txt">xLazyLoader</a> plugin for jQuery.  It shouldn&#8217;t be surprising that two independent developers might reach the same solution, and is just more proof that software patents are stupid. :)</p>
<p><strong>Update #2</strong> Added note about HTML5 async property on script tags.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/load-css-dynamically/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Selecting XML Nodes with JavaScript (Peril of getElementsByTagName)</title>
		<link>http://www.zachleat.com/web/selecting-xml-with-javascript/</link>
		<comments>http://www.zachleat.com/web/selecting-xml-with-javascript/#comments</comments>
		<pubDate>Sat, 10 May 2008 23:27:02 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/?p=132</guid>
		<description><![CDATA[Parsing XML in the browser can be a tricky beast.  There are many different wrong ways to do it, which can leave you cold and naked in a snowstorm if you're not careful.  So, let's put on the metaphorical electric one-sie of standards based code and let the power of Edison heat our JavaScript code like the innards of a <a href="http://starwars.wikia.com/wiki/Tauntaun">tauntaun</a>.]]></description>
			<content:encoded><![CDATA[<p><em>There are two popular camps for ajax data formats right now: XML and JSON.  Both have their (dis-)advantages.  The purpose of this article is  to show you how to effectively parse XML in the browser.</em></p>
<h3>Super Fast Beginner&#8217;s Primer</h3>
<ul>
<li>Case 1: <strong>Node</strong> (or un-namespaced node, null-namespaced node): a node without a prefix, such as child here:<br />
<code>&lt;child/&gt;</code></li>
<li>Case 2: <strong>Default namespaced node</strong>: a node without a prefix, but a parent node (or itself) has a xmlns attribute, like both root and child here:<br />
<code>&lt;root xmlns="http://example.com/"&gt;&lt;child/&gt;&lt;/root&gt;</code></li>
<li>Case 3: <strong>Namespaced node</strong>: a node with a prefix, and a parent node (or itself) declaring a xmlns with that prefix attached, like both child and root here:<br />
<code>&lt;prefix:root prefix:xmlns="http://example.com/"&gt;&lt;prefix:child/&gt;&lt;/root&gt;</code></li>
</ul>
<h3>/End Primer</h3>
<p>Parsing XML in the browser can be a tricky beast.  There are many different wrong ways to do it, which can leave you cold and naked in a snowstorm if you&#8217;re not careful.  So, let&#8217;s put on the metaphorical electric one-sie of standards based code and let the power of Edison heat our JavaScript code like the innards of a <a href="http://starwars.wikia.com/wiki/Tauntaun">tauntaun</a>.</p>
<p>If there is one thing you can take away from this article, its that the problems with XML in JavaScript have already been solved, and there is library code out there to do the job for you.  But libraries aren&#8217;t a substitute for knowledge (abstraction is a dangerous thing during education), so let&#8217;s learn <strong>why</strong> these problems are occurring so we can wrinkle our gray matter and increase our productivity at the same time.</p>
<h2>Use Cases</h2>
<p>These are the main use cases that takes place when selecting a node inside of an XML document:</p>
<ol>
<li><strong>Case 1</strong>: Selecting un-namespaced nodes (or nodes in the null namespace):

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;root<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;child</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This one is easy.  If you can guarantee that your XML will never have any namespaces, you&#8217;re home free.  Take your get out of jail free card and run for the hills.  Using this assumption, you can query nodes inside of your XML Document object using nothing other than <code>getElementsByTagName()</code>.  Lucky bastard.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// assume oDocEl is the documentElement inside of an XML Document </span>
<span style="color: #003366; font-weight: bold;">var</span> correctForCase1 <span style="color: #339933;">=</span> oDocEl.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'child'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li><strong>Case 2</strong>: Selecting default namespaced nodes:

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;root</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://example.com/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;child</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Tread lightly, this is about to get serious.  In most cases, historically I had thought that using the solution described for Case 1 would be sufficient in this case.  I had learned awhile back that Internet Explorer treats node names (including namespace prefix and local name together) as one string.  So, the method for Case 1 should work for Internet Explorer, especially in the case of node sans prefix.  In Firefox, you&#8217;d have to use getElementsByTagNS(), but that would be just a simple wrapper.</p>
<p>Then I met an Internet Explorer exception.  The only unique thing about this installation of Internet Explorer 7 was that it had MSXML 6 installed, when all the other computers I had tested on were using MSXML 3.  The obvious conclusion here is that MSXML 6 won&#8217;t select child nodes for Case 2.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> incorrectForCase2 <span style="color: #339933;">=</span> oDocEl.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'child'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here&#8217;s the right way to select nodes for Case 2.  Fair warning, to keep the code examples here simple, this solution requires Sarissa (sarissa.js and sarissa_ieemu_xpath.js) to be included on the page prior to usage.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// assume oDoc is an XML Document object.</span>
oDoc.<span style="color: #660066;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SelectionNamespaces&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;xmlns:whatever='http://example.com/'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> oDocEl <span style="color: #339933;">=</span> oDoc.<span style="color: #660066;">documentElement</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> correctForCase2A <span style="color: #339933;">=</span> oDocEl.<span style="color: #660066;">selectNodes</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'whatever:child'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> correctForCase2B <span style="color: #339933;">=</span> oDocEl.<span style="color: #660066;">selectSingleNode</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'whatever:child'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note how we&#8217;ve mapped what was the default namespace (without a prefix) to be a namespace WITH a prefix during the node selection.</p>
<p>It should be noted that when the resultant XML has a namespace attached (Case 2 and 3), Firefox works fine using getElementsByTagNameNS.  IE doesn&#8217;t include support for that method, however, so we&#8217;re forced to find a more complete solution.
</li>
<li><strong>Case 3</strong>: Select a non-default namespaced node:

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;root</span> <span style="color: #000066;">prefix:xmlns</span>=<span style="color: #ff0000;">&quot;http://example.com/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;prefix:child</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>As I mentioned in Case 2, normally (pre-MSXML 6), you&#8217;d be able to perform a <code>getElementsByTagName('prefix:child')</code> in IE and use getElementsByTagNameNS in Firefox as usual.  But that has changed now.  We need to set up the SelectionNamespaces property for IE, and we&#8217;ll use Sarissa to take it cross-browser for us.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// assume oDoc is an XML Document object.</span>
oDoc.<span style="color: #660066;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SelectionNamespaces&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;xmlns:whatever='http://example.com/'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> oDocEl <span style="color: #339933;">=</span> oDoc.<span style="color: #660066;">documentElement</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> correctForCase3A <span style="color: #339933;">=</span> oDocEl.<span style="color: #660066;">selectNodes</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'whatever:child'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> correctForCase3B <span style="color: #339933;">=</span> oDocEl.<span style="color: #660066;">selectSingleNode</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'whatever:child'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Note, this is the same code as Case 2 (which is a good thing)</span></pre></div></div>

<p>Note that we did <em>not</em> have to use the same prefix that was defined by the result XML.  We can map it to whatever we want (literally).
</li>
</ol>
<h2>Why is this important?</h2>
<p>Because most libraries don&#8217;t handle Case 2 and Case 3, which are important parts of XML.  Here&#8217;s some code straight from YUI 2.5.1 (DataSource component):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Line 1394</span>
<span style="color: #003366; font-weight: bold;">var</span> xmlNode <span style="color: #339933;">=</span> result.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xmlNode <span style="color: #339933;">&amp;&amp;</span> xmlNode.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> xmlNode.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    data <span style="color: #339933;">=</span> xmlNode.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
       data <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice how they just do getElementsByTagName.  For shame :(  jQuery doesn&#8217;t handle Case 2 or Case 3 either.  (Proof is an exercise to the reader :P)  So, if you have XML data sources with namespaces, it would do you well to use the solution presented in this article, or you&#8217;re going to have headaches later.</p>
<h2>Springer&#8217;s Final Word</h2>
<p>Don&#8217;t use getElementsByTagName.  If you do, PLEASE include a note saying that your code isn&#8217;t going to support namespaced XML.  Branch your selection code to check if Sarissa has been included on the page, and use Sarissa for namespaced XML if it&#8217;s there.  It&#8217;s not fun to be pidgin-holed into the simplest case of XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/selecting-xml-with-javascript/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Rethinking JavaScript Grids and DataTables</title>
		<link>http://www.zachleat.com/web/rethinking-javascript-grids-and-datatables/</link>
		<comments>http://www.zachleat.com/web/rethinking-javascript-grids-and-datatables/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 20:29:26 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[Interface Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Conservative Design]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/?p=122</guid>
		<description><![CDATA[In the world of front end engineering, one must consider the end-user of the interface first, and above all other things. The priorities should not start with development ease, nor external library preference. The priorities should start with the needs of the consumer of your end product. Evolution of your engineering skill is also a [...]]]></description>
			<content:encoded><![CDATA[<p>In the world of front end engineering, one must consider the end-user of the interface first, and above all other things.  The priorities should not start with development ease, nor external library preference.  The priorities should start with the needs of the consumer of your end product.</p>
<p>Evolution of your engineering skill is also a vital trait in this world, which means that as a developer increases his knowledge of good practices and proper methods, sometimes he must shirk his previous assertions about the world as he previously knew it.  And today I&#8217;m shirking a staple of the front end as all web users know it: The Grid (DataTable) Component.</p>
<p>Of course, I&#8217;ve written a few articles in the past about the <a href="http://developer.yahoo.com/yui/datatable/">YUI DataTable</a>, during my long love affair with Yahoo&#8217;s User Interface library.  Another popular one is jQuery&#8217;s <a href="http://tablesorter.com/docs/">TableSorter</a>.  Then there&#8217;s the <a href="http://dojotoolkit.org/book/dojo-book-0-9/docx-documentation-under-development/grid">Dojo Grid</a>, a component <a href="http://www.sitepen.com/blog/2007/09/16/the-dojo-grid/">inherited from TurboAjax</a>.  ExtJS has a variety of nice examples as well for their <a href="http://extjs.com/deploy/dev/examples/#sample-1">Ext 2.0 Grid</a>.</p>
<p>And after using these Grids and DataTables, I certainly respect the programming that went into developing these components.  But let&#8217;s take a step back for a second.  Why do the users need the bells and whistles in these components?  Are they worth the extra load time and complexity they add to the interface?</p>
<p>All we&#8217;re doing here is putting a nice coat of paint on a &lt;table&gt; tag.  Sure, it might have some nice ancillary features like Ajax Data Loading, but those don&#8217;t really matter &#8211; they are things that can be easily performed with some good Ajax and DOM insert utility functions.  In fact, most of the core features included in these components could be described as feature creep, and not beneficial to the end user at all.  Feature creep contributes to code bloat, which means the user is downloading bytes to their web browser that they don&#8217;t need, which can hamper performance.  Libraries usually have online examples of their components, and the include sizes are seen below.  (Gzip compression not considered)</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>JavaScript Size</th>
<th>Minimized</th>
<th>Link</th>
</tr>
</thead>
<tbody>
<tr>
<td>YUI DataTable</td>
<td>216.6 KB</td>
<td>Minimized</td>
<td><a href="http://developer.yahoo.com/yui/examples/datatable/dt_basic_clean.html">Example</a></td>
</tr>
<tr>
<td>Dojo Grid</td>
<td>338.4 KB</td>
<td>Unminimized</td>
<td><a href="http://dojotoolkit.org/book/dojo-book-0-9/docx-documentation-under-development/grid/simple-grid">Example</a></td>
</tr>
<tr>
<td>Ext Grid</td>
<td>545.5 KB</td>
<td>Minimized</td>
<td><a href="http://extjs.com/deploy/dev/examples/grid/array-grid.html">Example</a></td>
</tr>
<tr>
<td>jQuery TableSorter</td>
<td>66 KB</td>
<td>Minimized</td>
<td><a href="http://www.tablesorter.com/">Example</a></td>
</tr>
</tbody>
</table>
<p>The JavaScript include sizes listed above are directly proportional to the feature set that the components provide, and should give you an idea of the overhead involved with using them.  Do we need 545.5 KB of features coming down the pipe to give our users an extra bell, or an extra whistle?  Let&#8217;s analyze the features to rationalize their usage, and remove items from the feature set.</p>
<ul>
<li>Sorting</li>
<li>Modifying column order and display</li>
<li>Resizing columns</li>
<li>Editing of row data directly on the grid itself</li>
<li>Scrolling</li>
<li>Pagination</li>
</ul>
<p><strong>Sorting</strong></p>
<p>Data should be used in the context of its usefulness.  You have a list of messages in your e-mail inbox.  What&#8217;s the most useful context for this list?  In order of date received.  The default sort order provided by the application, to facilitate proper use of the application.  Is comparing the rows in the grid by any other method as useful?  Does the user need to see the list of messages ordered alphabetically by subject?  In these cases where the user is in need of a specific message, <em>searching and filtering</em> is more useful than sorting.  The default sort is useful, but allowing the user to resort on the client, in most cases, is not as useful as other methods of finding a row.</p>
<p><strong>Modifying column order and display</strong></p>
<p>The same argument can be made for any of the other methods of customization provided to the end user.  Does the user need to reorder or hide columns?  The context provided by the application should be sufficient to use the applications data in the way it was intended.  Don&#8217;t overcomplicate your user interface with needless features or a deluge of useless data.  Provide succinct, appropriate data, and the user needn&#8217;t reorder or change the interface.</p>
<p><strong>Resizing columns</strong></p>
<p>The default HTML &lt;table&gt; tag expands to fit the data inside of its cells.  Even when you set the width of the table explicitly, the cells adjust themselves accordingly to fit the data.  This should be the behavior of your table.  You needn&#8217;t monkey around with widths, the browser is smart enough to do it for you.  You can even customize a cell to wrap its text to multiple lines with CSS, if need be.</p>
<p><strong>Editing of row data directly on the grid itself</strong></p>
<p>If you&#8217;re providing an Excel spreadsheet interface for the end user to customize your data, you haven&#8217;t designed your interface correctly.  Rethink how the user needs to interact with the data you&#8217;ve provided, and give them a better, simpler way to edit the data.</p>
<p><strong>Scrolling</strong></p>
<p>Everyone knows that internal scrollbars on a page are evil.  I don&#8217;t even like scrollbars on textareas, to be honest.  Previously, I had worked and reworked the YUI DataTable to handle horizontal scrolling.  Looking back on this, it was a mistake.  There are better ways to handle lots of data in a table, without the heavy mouse interaction and scanning that scrolling require.  Which brings me to my next point.</p>
<p><strong>Pagination</strong></p>
<p>This is the one exception to the feature set cutting board.  This is the one feature that&#8217;s is a requirement, when the data set has too many records to fit on a single page.</p>
<p>Keep these in mind, and look at the feature set provided by a few sites using tabular data centric interfaces that know a thing or two about interface design:</p>

<a href='http://www.zachleat.com/web/rethinking-javascript-grids-and-datatables/gmail/' title='Google Mail'><img width="150" height="150" src="http://www.zachleat.com/web/wp-content/uploads/2008/04/gmail-150x150.png" class="attachment-thumbnail" alt="Google Mail" title="Google Mail" /></a>
<a href='http://www.zachleat.com/web/rethinking-javascript-grids-and-datatables/wordpress-admin/' title='Wordpress 2.5 Admin Interface'><img width="150" height="150" src="http://www.zachleat.com/web/wp-content/uploads/2008/04/wordpress-admin-150x150.png" class="attachment-thumbnail" alt="Wordpress 2.5 Admin Interface" title="Wordpress 2.5 Admin Interface" /></a>
<a href='http://www.zachleat.com/web/rethinking-javascript-grids-and-datatables/google-reader/' title='Google Reader List View'><img width="150" height="150" src="http://www.zachleat.com/web/wp-content/uploads/2008/04/google-reader-150x150.png" class="attachment-thumbnail" alt="Google Reader List View" title="Google Reader List View" /></a>

<p><strong>So, what should we include?</strong></p>
<p>A simple CSS class to style your table is sufficient, with links to paginate the table (properly) and/or a hover for row selection if needed.  You&#8217;re looking at 10-20 lines of jQuery code, maximum, and a few CSS declarations.  In lieu of sorting, of course, you&#8217;ll need to program in a mechanism for searching and filtering as well.  But really, the difficulty with programming this component is knowing what to leave out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/rethinking-javascript-grids-and-datatables/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Faster YUI DataTable with 5 Lines of Code</title>
		<link>http://www.zachleat.com/web/faster-yui-datatable-with-5-lines-of-code/</link>
		<comments>http://www.zachleat.com/web/faster-yui-datatable-with-5-lines-of-code/#comments</comments>
		<pubDate>Fri, 28 Dec 2007 00:34:56 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/12/27/faster-yui-datatable-with-5-lines-of-code/</guid>
		<description><![CDATA[Holy Reflows Batman! The typical usage of a DataTable in the Yahoo User Interface JavaScript library involves passing a string into the constructor signifying the ID attribute of the container you want to attach the DataTable to. However, the YUI DataTable loves the DOM and creating nodes individually using DOM methods. Normally that&#8217;d be fine, [...]]]></description>
			<content:encoded><![CDATA[<p>Holy Reflows Batman!  The typical usage of a DataTable in the Yahoo User Interface JavaScript library involves passing a string into the constructor signifying the ID attribute of the container you want to attach the DataTable to.  However, the YUI DataTable loves the DOM and creating nodes individually using DOM methods.  Normally that&#8217;d be fine, but one of the first things it does in the constructor is create the table element and attach it to the live DOM.  This is a no-no.  Now, every time they append a new node (for a new row or a new cell inside of a row), it causes a reflow in the browser!  What does this mean?  Really bad lag when you insert 40 or 50 rows.  Recognize this piece of code?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myDataTable <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> YAHOO.<span style="color: #660066;">widget</span>.<span style="color: #660066;">DataTable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;myContainer&quot;</span><span style="color: #339933;">,</span> myColumnDefs<span style="color: #339933;">,</span> myDataSource<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Straight from the docs.  No no no!</p>
<p>Instead, you should pass in an unattached DOM node instead of a string!</p>
<p>Try this code on for size:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myDataTable <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> YAHOO.<span style="color: #660066;">widget</span>.<span style="color: #660066;">DataTable</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> myColumnDefs<span style="color: #339933;">,</span> myDataSource<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
myDataTable.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'initEvent'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> d <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myContainer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// CHANGE THIS -- match the id of the container you want.</span>
    <span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>d.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> d.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>d.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// remove previous DataTables</span>
    d.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._elContainer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/faster-yui-datatable-with-5-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Write More Efficient Javascript in YUI with CSS Selectors</title>
		<link>http://www.zachleat.com/web/write-more-efficient-javascript-in-yui-with-css-selectors/</link>
		<comments>http://www.zachleat.com/web/write-more-efficient-javascript-in-yui-with-css-selectors/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 22:36:05 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[CSS Selectors]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/09/03/write-more-efficient-javascript-in-yui-with-css-selectors/</guid>
		<description><![CDATA[This is an updated version of a previous article entitled Using DOM Query Libraries in YUI for the new version of YAHOO.util.Dom included with YUI 2.3.0 as well as including support for passing context nodes into Dom functions. Here we are again. I just love those CSS Selectors. If you haven&#8217;t read Part One of [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is an updated version of a previous article entitled <a href="http://www.zachleat.com/web/2007/07/30/using-dom-query-libraries-in-yui/">Using DOM Query Libraries in YUI</a> for the new version of YAHOO.util.Dom included with YUI 2.3.0 as well as including support for passing context nodes into Dom functions.</em></p>
<p>Here we are again.  I just love those CSS Selectors.  If you haven&#8217;t read Part One of the series linked above, I would encourage it to get a little background on why we&#8217;re attempting this approach.</p>
<h1>Download the appropriate files:</h1>
<h1>Get the easy <strong>ALL-IN-ONE file</strong>: <a href="/Lib/Y2/Y2.js">Y2.js</a> (31 KB original source) OR <a href="/Lib/Y2/Y2-p.js">Y2-p.js</a> (11 KB minimized)</h1>
<h2>Get the files separately (if you want to use a custom selector library, or have already included DomQuery or jQuery): <a href="/Lib/Y2/Y2-solo.js">Y2-solo.js</a> (9 KB original source) OR <a href="/Lib/Y2/Y2-solo-p.js">Y2-solo-p.js</a> (4 KB minimized)</h2>
<p>Also, first you&#8217;ll need to get Jack&#8217;s nice DomQuery class.</p>
<p>Download: <a href="/Lib/Y2/DomQuery.js">Jack Slocum&#8217;s DomQuery Standalone File (24 KB)</a> 1.0 Alpha 3 &#8211; Rev 4<br />
Download: <a href="/Lib/Y2/DomQuery-packer.js">Jack Slocum&#8217;s DomQuery Standalone File Packed (7 KB)</a> 1.0 Alpha 3 &#8211; Rev 4</p>
<p>You can use the jDomQuery standalone, or any jQuery version, (instead of DomQuery) linked in the previous article, but there is an unresolved bug with the getRegion method since jQuery doesn&#8217;t return actual Array&#8217;s.  But if you&#8217;re not using that method, have at it.</p>
<h1>What can I do with it?</h1>
<p>I have not included ALL functions in this class, only the ones that take nodes in as arguments.  If you use these functions, you are encouraged to use the unmodified versions contained in YAHOO.util.Dom.  Functions not included here: getClientHeight, getClientWidth, getDocumentHeight, getDocumentScrollLeft, getDocumentScrollTop, getDocumentWidth, getViewportHeight, getViewportWidth.</p>
<p>Let&#8217;s see some documentation on this mother (if you&#8217;re wondering what the original functions do, see the <a href="http://developer.yahoo.com/yui/docs/YAHOO.util.Dom.html">original documentation</a>).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// this is the test context node we're going to pass in</span>
<span style="color: #003366; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'context'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>addClass</h1>
<p>Adds a CSS class to first matching node.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns void</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClassContext'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>addClassAll</h1>
<p>Adds a CSS class to all matching nodes.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns void</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClassAll</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClassAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClassContext'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>hasClass</h1>
<p>Tests the first result node returned to see if it has a CSS class.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Booleans.</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClassContext'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>hasClassAll</h1>
<p>Tests all matching nodes to see if they have a CSS class.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of Booleans.</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClassAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClassAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div div:last'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClassContext'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>removeClass</h1>
<p>Removes a CSS class from first matched node.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Boolean (misdocumented on the YAHOO.util.Dom page)</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>removeClassAll</h1>
<p>Removes a CSS class from all matched nodes.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of Booleans (misdocumented on the YAHOO.util.Dom page)</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClassAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClassAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>replaceClass</h1>
<p>Replaces a CSS class on first matched node with a new CSS class, or adds it if the old CSS class doesn&#8217;t exist.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Boolean (misdocumented on the YAHOO.util.Dom page)</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">replaceClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'fourth'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">replaceClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'fourth'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>replaceClassAll</h1>
<p>Replaces a CSS class on all matched nodes with a new CSS class, or adds it if the old CSS class doesn&#8217;t exist.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of Booleans (misdocumented on the YAHOO.util.Dom page)</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">replaceClassAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'fourth'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">replaceClassAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'fourth'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>get</h1>
<p>Get first matched node.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div b'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getAll</h1>
<p>Get all matched nodes.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div b'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>batch</h1>
<p>Executes a function against first matched node.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns single return value from the function</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">batch</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second b'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el<span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">batch</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div b'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el<span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>batchAll</h1>
<p>Executes a function against all matched nodes.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of return values from the function</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">batchAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second b'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el<span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">batchAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div b'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el<span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>generateId</h1>
<p>Generates and assigns a unique ID attribute if not present on first matched element.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns String (new ID attribute)</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.first'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>generateIdAll</h1>
<p>Generates and assigns a unique ID attribute if not present on matched elements.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of String (new ID attributes)</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">generateIdAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.first'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">generateIdAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getChildren</h1>
<p>Gets all HTMLElement children of the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getChildren</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getChildren</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getChildrenBy</h1>
<p>Returns all HTMLElement children of the first matched node that pass a Boolean function test. (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getChildrenBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'theMiddleB'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getChildrenBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'theMiddleB'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getAncestorBy</h1>
<p>Returns the first HTMLElement ancestor of the first matched node that passes a Boolean function test. (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAncestorBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'context'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAncestorBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'context'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getAncestorByClassName</h1>
<p>Returns the first HTMLElement ancestor of the first matched node that has a CSS Class. (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAncestorByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'contextClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAncestorByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'contextClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getAncestorByClassName</h1>
<p>Returns the first HTMLElement ancestor of the first matched node that is a certain tag (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAncestorByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getAncestorByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getFirstChild</h1>
<p>Returns the first HTMLElement child of the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getFirstChild</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getFirstChild</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getFirstChildBy</h1>
<p>Returns the first HTMLElement child that passes a boolean function test from the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getFirstChildBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'theMiddleB'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getFirstChildBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'theMiddleB'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getLastChild</h1>
<p>Returns the last HTMLElement child of the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getLastChild</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getLastChild</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getLastChildBy</h1>
<p>Returns the last HTMLElement child that passes a boolean function test from the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getLastChildBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'theMiddleB'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getLastChildBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'theMiddleB'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getNextSibling</h1>
<p>Returns the next HTMLElement sibling of the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getNextSibling</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getNextSibling</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getNextSiblingBy</h1>
<p>Returns the next HTMLElement sibling that passes a boolean function test from the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getNextSiblingBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'third'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getNextSiblingBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getPreviousSibling</h1>
<p>Returns the previous HTMLElement sibling of the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getPreviousSibling</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getPreviousSibling</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getPreviousSiblingBy</h1>
<p>Returns the previous HTMLElement sibling that passes a boolean function test from the first matched node (does not include text nodes or whitespace)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getPreviousSiblingBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> el.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'third'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getPreviousSiblingBy</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span><span style="color: #3366CC;">'third'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getRegion</h1>
<p>Gets the <a href="http://developer.yahoo.com/yui/docs/YAHOO.util.Region.html">Region</a> containing the first matched element.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns &lt;a href=&quot;http://developer.yahoo.com/yui/docs/YAHOO.util.Region.html&quot;&gt;YAHOO.util.Region&lt;/a&gt;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getRegion</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getRegion</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getRegionAll</h1>
<p>Gets all <a href="http://developer.yahoo.com/yui/docs/YAHOO.util.Region.html">Regions</a> containing all matched elements.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of &lt;a href=&quot;http://developer.yahoo.com/yui/docs/YAHOO.util.Region.html&quot;&gt;YAHOO.util.Region&lt;/a&gt;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getRegionAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.myClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getRegionAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.myClass'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>setStyle</h1>
<p>Sets the style for the first matched node</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns void</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'1px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'10px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>setStyleAll</h1>
<p>Sets style for all matched nodes</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns void</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setStyleAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'1px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setStyleAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'10px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getStyle</h1>
<p>Gets a specific style property from the first matched node</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns String of specific style property</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getStyleAll</h1>
<p>Gets a specific style property from all matched nodes</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of Strings of specific style property</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getStyleAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getStyleAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>setX, setY, setXY</h1>
<p>Sets the horizontal placement (X), vertical placement (Y), or both (XY) of the first matched element</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns void</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setX</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setX</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setXY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">120</span><span style="color: #339933;">,</span><span style="color: #CC0000;">120</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setXY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">120</span><span style="color: #339933;">,</span><span style="color: #CC0000;">120</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>setXAll, setYAll, setXYAll</h1>
<p>Sets the horizontal placement (X), vertical placement (Y), or both (XY) of all matched elements</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns void</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setXAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setXAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setXYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">120</span><span style="color: #339933;">,</span><span style="color: #CC0000;">120</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setXYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">120</span><span style="color: #339933;">,</span><span style="color: #CC0000;">120</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getX, getY, getXY</h1>
<p>Gets the horizontal placement (X), vertical placement (Y), or both (XY) of the first matched element</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Integer</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getXY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getXY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>getXAll, getYAll, getXYAll</h1>
<p>Gets the horizontal placement (X), vertical placement (Y), or both (XY) of all matched elements</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Array of Integers</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getXAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getXAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getXYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getXYAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>inDocument</h1>
<p>Find out whether the first matched element is in the current document</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns Boolean</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">inDocument</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">inDocument</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>insertAfter</h1>
<p>Take the first matched node of the first selector and insert after the first matched node of the second selector</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Note that this function handles context nodes on the first or second selectors, both, or none.</span>
<span style="color: #006600; font-style: italic;">// returns the moved HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>insertBefore</h1>
<p>Take the first matched node of the first selector and insert before the first matched node of the second selector</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Note that this function handles context nodes on the first or second selectors, both, or none.</span>
<span style="color: #006600; font-style: italic;">// returns the moved HTMLElement</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.third'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'div.fourth'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>isAncestor</h1>
<p>Find out whether the first matched node of the first selector is an ancestor of the first matched node of the second selector.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Note that this function handles context nodes on the first or second selectors, both, or none.</span>
<span style="color: #006600; font-style: italic;">// return Boolean</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">isAncestor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'b#theFirstB'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">isAncestor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'b#theFirstB'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">isAncestor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'b#theFirstB'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Y2.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">isAncestor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.second'</span><span style="color: #339933;">,</span> context<span style="color: #339933;">,</span><span style="color: #3366CC;">'b#theFirstB'</span><span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(Documentation is a bitch!)</p>
<h1>Additional Information</h1>
<ul>
<li><a href="http://www.zachleat.com/Projects/Y2/test.html">Run the test document.</a> (Might convert this to YUI Test framework if there is enough interest in this extension)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/write-more-efficient-javascript-in-yui-with-css-selectors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enlarging your YUI DataTable in 29 Seconds or Less!</title>
		<link>http://www.zachleat.com/web/enlarging-your-yui-datatable-in-29-seconds-or-less/</link>
		<comments>http://www.zachleat.com/web/enlarging-your-yui-datatable-in-29-seconds-or-less/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 03:09:48 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[Expandable]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/08/28/enlarging-your-yui-datatable-in-29-seconds-or-less/</guid>
		<description><![CDATA[This is an updated version of the Enlarging your YUI DataTable in 30 Seconds or Less! modified for the newly released YUI 2.3.0. This method adds an extra row to the YUI DataTable when a row is selected, below the selected row. This allows the developer to add additional content that might not be applicable [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is an updated version of the <a href="http://www.zachleat.com/web/2007/06/07/enlarging-your-yui-datatable-in-30-seconds-or-less/">Enlarging your YUI DataTable in 30 Seconds or Less!</a> modified for the newly released YUI 2.3.0.</em></p>
<p>This method adds an extra row to the YUI DataTable when a row is selected, below the selected row.  This allows the developer to add additional content that might not be applicable to the column constraints of a typical datatable or grid and allow that content be displayed more fluidly inside a single row spanning all of the viewable columns.</p>
<p>I know you&#8217;re anxious for an example, so let&#8217;s see some screenshots of a simple YUI DataTable:</p>
<p><a href="http://www.zachleat.com/Lib/ymod/ymod-tableExtension-2.3.0.html"><img src='http://www.zachleat.com/web/wp-content/uploads/2007/08/default-datatable.gif' alt='Default DataTable' /></a></p>
<p>Turns into this when a row is selected:</p>
<p><a href="http://www.zachleat.com/Lib/ymod/ymod-tableExtension-2.3.0.html"><img src='http://www.zachleat.com/web/wp-content/uploads/2007/08/datatable-selected.gif' alt='Row selected' /></a></p>
<p>Click any of the above images for a live example.</p>
<p>Any HTML can be added.  You can make an AJAX call and put the result into the newly inserted row (that will be left as an exercise for the reader [you]).</p>
<p>I know you&#8217;re asking yourself, how the hell do I add this to my YUI DataTable?  WHERE IS THE DAMN SOURCE CODE?  Calm down, you know I&#8217;m getting to it.</p>
<h3>How To</h3>
<p>1. Include the <a href="http://www.zachleat.com/Lib/ymod/ymod-tableExtension-2.3.0.js">ymod-tableExtension-2.3.0.js</a> file.<br />
2. Create your DataTable.  If you don&#8217;t know how to do this, go to the <a href="http://developer.yahoo.com/yui/datatable/">official documentation for help and examples</a>.<br />
3. Make sure your DataTable has the selectionMode parameter set to &#8216;single&#8217;.  This can be achieved by passing in <code>{ selectionMode: 'single' }</code> in as the 4th argument to the DataTable constructor.<br />
4. Use the following code to setup your table extension:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// myDataTable is your DataTable object</span>
YAHOO.<span style="color: #660066;">ymod</span>.<span style="color: #660066;">tableExtension</span>.<span style="color: #660066;">setup</span><span style="color: #009900;">&#40;</span> myDataTable<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> contentDiv <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> myContent <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> selectedRows <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getSelectedRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> selectedRows.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        myContent <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'Do something based on&lt;br /&gt;the row that is selected!'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    contentDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> myContent<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The setup function is basically a convenience method to add the event listeners.  You can just as easily do this yourself manually:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// myDataTable is your DataTable object.</span>
myDataTable.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'headerRowMousedownEvent'</span><span style="color: #339933;">,</span> YAHOO.<span style="color: #660066;">ymod</span>.<span style="color: #660066;">tableExtension</span>.<span style="color: #660066;">cleanUp</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myDataTable.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'rowClickEvent'</span><span style="color: #339933;">,</span> YAHOO.<span style="color: #660066;">ymod</span>.<span style="color: #660066;">tableExtension</span>.<span style="color: #660066;">selectRow</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> contentDiv <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009966; font-style: italic;">/* same as function appears above */</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>CSS</h3>
<p>Here&#8217;s some CSS hooks to do some styling.  The expanded row will include the yui-dt-selected class by default.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* The original table row clicked on */</span>
tr.<span style="color: #660066;">ymod</span><span style="color: #339933;">-</span>expanded <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009966; font-style: italic;">/* Row containing the expanded content */</span>
tr.<span style="color: #660066;">ymod</span><span style="color: #339933;">-</span>expandedData <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009966; font-style: italic;">/* Div containing the expanded content inside the row */</span>
tr.<span style="color: #660066;">ymod</span><span style="color: #339933;">-</span>expandedData div.<span style="color: #660066;">ymod</span><span style="color: #339933;">-</span>expandedDataContent <span style="color: #009900;">&#123;</span> background<span style="color: #339933;">-</span>color<span style="color: #339933;">:</span> navy<span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> 2px 6px<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Limitations</h3>
<p> &#8211; Resorting removes the expanded content.  Otherwise it was messing with the sort.<br />
 &#8211; It only works with single row selection mode, which allows only one row to be selected at a time.  This is not the default (standard), which allows multiple rows to be selected with SHIFT or CTRL.  Feel free to modify this to work with other modes!</p>
<h1><a href="http://www.zachleat.com/Lib/ymod/ymod-tableExtension-2.3.0.js">Download ymod-tableExtension-2.3.0.js</a></h1>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/enlarging-your-yui-datatable-in-29-seconds-or-less/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Namespacing outside of the YAHOO Namespace</title>
		<link>http://www.zachleat.com/web/namespacing-outside-of-the-yahoo-namespace/</link>
		<comments>http://www.zachleat.com/web/namespacing-outside-of-the-yahoo-namespace/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 01:34:24 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Namespacing]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/08/28/namespacing-outside-of-the-yahoo-namespace/</guid>
		<description><![CDATA[YAHOO.namespace(). A lovely little utility function subject that I&#8217;ve written about before. If you&#8217;ve never heard of YAHOO.namespace or aren&#8217;t even familiar with namespacing, I&#8217;d read that article first. I&#8217;ll be honest, using the YAHOO namespace to store my own code makes my bunghole tighten just a little bit. What if I had written code [...]]]></description>
			<content:encoded><![CDATA[<p>YAHOO.namespace().  A lovely little utility function subject that <a href="http://www.zachleat.com/web/2007/08/09/yui-code-review-yahoonamespace/">I&#8217;ve written about before</a>.  If you&#8217;ve never heard of YAHOO.namespace or aren&#8217;t even familiar with namespacing, I&#8217;d read that article first.</p>
<p>I&#8217;ll be honest, using the YAHOO namespace to store my own code makes my bunghole tighten just a little bit.  What if I had written code stored under YAHOO.tool, which was unused prior to YUI 2.3.0?  What would I do now?  I&#8217;d have to rewrite my code, or never include any of the wonderful <code>YAHOO.tool.TestCase</code>, put together by <a href="http://www.nczonline.net/">Nicholas Zakas</a>.  As is traditional with most of my weblog posts, I try not to just complain about a problem without giving you a solution (but let&#8217;s be honest, only if it doesn&#8217;t take too much work).</p>
<p>Let&#8217;s rewrite the YAHOO.namespace function to work outside of the YAHOO Namespace, so we can do things like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'zachsWorld.partyTime'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
zachsWorld.<span style="color: #660066;">partyTime</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Excellent.'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
zachsWorld.<span style="color: #660066;">partyTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// obviously would alert: Excellent.</span></pre></div></div>

<p>Here&#8217;s some code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">,</span> o<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">,</span> d<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>a.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">=</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        d<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        o<span style="color: #339933;">=</span>window<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>d.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">=</span>j<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            o<span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Obviously this is just a modification of the YAHOO.namespace function.  I&#8217;d recommend putting this under your own namespace (I&#8217;m trying to put most of the code I write on this website under the Y2 namespace, but everyone should have their own parent namespace), like so (any namespaces you create using this function won&#8217;t use the parent namespace assigned here by default):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> Y2 <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> Y2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
Y2.<span style="color: #003366; font-weight: bold;">namespace</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009966; font-style: italic;">/* copy function contents from above. */</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But you can do whatever you want.  This is one of the functions that I think separates YUI from the other frameworks out there, giving an easy utility to organize your code.  This is something I think jQuery seriously lacks, noting from the code inside the many jQuery plugins contributed by end users.  Many jQuery contributors do not organize their code, putting multiple unnecessary top level functions into jQuery.fn as methods, or into the jQuery object itself as functions.  People whine about polluting the global namespace&#8230; I suppose it might be considered nitpickey to whine about the jQuery namespace.  Okay you whiney bastard, let&#8217;s help out and put this into jQuery!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// include jQuery first.</span>
jQuery.<span style="color: #003366; font-weight: bold;">namespace</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">,</span> o<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">,</span> d<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>a.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">=</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        d<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        o<span style="color: #339933;">=</span>window<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>d.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">=</span>j<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            o<span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Please note, this method does NOT work using jQuery methods with an element context, such as jQuery(&#8216;div&#8217;).myNamespace.myMethod().  Your element context won&#8217;t be carried through to myMethod().</p>
<p>However, you can use it for jQuery functions, such as this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// definition</span>
jQuery.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'jQuery.debug'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test1</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'test1 function'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test2</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'test2 function'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// usage</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For more information, you can read <a href="http://yuiblog.com/blog/2006/06/01/global-domination/">Global Domination, an article written by Douglas Crockford</a>, or <a href="http://docs.jquery.com/Plugins/Authoring">Best Practices for Writing jQuery plugins</a>.</p>
<p><b>Updated</b>: fixed some weird source parsing errors introduced by the code formatting plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/namespacing-outside-of-the-yahoo-namespace/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>YUI Code Review: YAHOO.namespace</title>
		<link>http://www.zachleat.com/web/yui-code-review-yahoonamespace/</link>
		<comments>http://www.zachleat.com/web/yui-code-review-yahoonamespace/#comments</comments>
		<pubDate>Fri, 10 Aug 2007 00:28:46 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Namespacing]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/08/09/yui-code-review-yahoonamespace/</guid>
		<description><![CDATA[This is the first in a one+ part series of posts (the + is optional) reviewing the actual code contained in the YUI library. This series is not intended for advanced JavaScripters, so if you&#8217;re insulted by reading things you already know, you probably aren&#8217;t a very good student. YAHOO.namespace. This is a great little [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the first in a one+ part series of posts (the + is optional) reviewing the actual code contained in the YUI library.  This series is not intended for advanced JavaScripters, so if you&#8217;re insulted by reading things you already know, you probably aren&#8217;t a very good student.</em></p>
<p>YAHOO.namespace.  This is a great little utility function that gives you an easy way to encourage low coupling throughout your JavaScript code.  Divide your functions into functional units!  If you already know how to use this function, you can skip to the bottom to learn a few JavaScript tricks Yahoo has put in.  If not, keep reading!  Are you making a new package you want to put under the YAHOO namespace?  Just declare it in a string argument passed into the YAHOO.namespace function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will create a YAHOO.myNamespace object that can be used many different ways.  You can assign a single function to it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #660066;">myNamespace</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
YAHOO.<span style="color: #660066;">myNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Or you can assign multiple functions to it (with private variables included) using the <a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">amazing Module Pattern</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #660066;">myNamespace</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> myPrivateVariable<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
		myFirstFunction<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> myPrivateVariable<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		mySecondFunction<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> hisOrHerPrivateVariable <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">myNamespace</span>.<span style="color: #660066;">myFirstFunction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
YAHOO.<span style="color: #660066;">myNamespace</span>.<span style="color: #660066;">mySecondFunction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Did you know that you can pass multiple arguments into YAHOO.namespace?  I&#8217;ve been using YUI all this time and didn&#8217;t know about this feature.  But the more I think about it, the more I doubt it&#8217;s usefulness.  When are you going to declare two unrelated namespaces adjacently in code?  For example, doing this is redundant in YUI:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace.myNestedNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The second call to YAHOO.namespace will reuse &#8216;myNamespace&#8217; if it exists, and create it if it doesn&#8217;t.  But the point here is that you can do something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'myOtherNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>which will create YAHOO.myNamespace and YAHOO.myOtherNamespace, and return a reference to the last one created, in this case YAHOO.myOtherNamespace.</p>
<p>Here&#8217;s the code from this nice little function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">,</span> o<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">,</span> d<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>a .<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">=</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        d<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        o<span style="color: #339933;">=</span>YAHOO<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// YAHOO is implied, so it is ignored if it is included</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;YAHOO&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>d.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">=</span>j<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            o<span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<ol>
<li><code>var a=arguments</code>: They&#8217;re iterating over the arguments passed into the function to declare multiple simultaneously.  Arguments is the variable passed into every function that you can use if you want to handle a variable number of arguments.  You can also declare a few arguments in the function( myArg ) and use the arguments variable if you want.</li>
<li><code>j=(d[0] == "YAHOO") ? 1 : 0</code> They reuse the YAHOO top level object if not explicitly included into the declaration.  Start the index at 1 if YAHOO was declared to skip defining it twice.</li>
<li><code>o[d[j]]=o[d[j]] || {};</code> They reuse existing namespaces if they have already been created.  The OR || declaration means that Javascript will use {} (an empty object) if o[d[j]] is undefined.</li>
<p></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/yui-code-review-yahoonamespace/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using DOM Query Libraries in YUI</title>
		<link>http://www.zachleat.com/web/using-dom-query-libraries-in-yui/</link>
		<comments>http://www.zachleat.com/web/using-dom-query-libraries-in-yui/#comments</comments>
		<pubDate>Mon, 30 Jul 2007 07:37:03 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[CSS Selectors]]></category>
		<category><![CDATA[DED|Chain]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Packer]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/07/30/using-dom-query-libraries-in-yui/</guid>
		<description><![CDATA[Recently, I posted the top 8 things I thought the YUI Library needed to be a top tier JavaScript library again. One of those things included a CSS Selector DOM Querying class. Use one of these babies for awhile, and you&#8217;ll never be able to code without it again. They&#8217;re amazingly useful and will shorten [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I posted the top 8 things I thought the YUI Library needed to be a top tier JavaScript library again.  One of those things included a CSS Selector DOM Querying class.  Use one of these babies for awhile, and you&#8217;ll never be able to code without it again.  They&#8217;re amazingly useful and will shorten your code quite beautifully.</p>
<p>So, let&#8217;s plug one of them into YUI!  Let&#8217;s get some of that power under the hood.  And let&#8217;s make it work identically to how we write our code for YUI currently, instead of changing the coding style (a la Dustin Diaz&#8217;s great extension to YUI called <a href="http://dedchain.dustindiaz.com/">DED|Chain</a>).</p>
<p>How are we going to do this?  Let&#8217;s dive into the shallow end of the pool.</p>
<p>The include order of our javascript files is going to be important.  So, first we&#8217;ll do the YUI library core file (either yahoo-dom-event.js or utilities.js depending on your need for animation).  Next, we need to include a CSS Selector DOM Querying class.  For this proof of concept, I&#8217;ve provided examples for my two favorites, the jQuery engine and Jack Slocum&#8217;s DomQuery.  These files are released under the MIT license, so make sure that complies with your project.  It&#8217;s pretty liberal, so you shouldn&#8217;t have any problems.  If you find these querying libraries useful, please donate to these projects!</p>
<p>For code simplicity, I&#8217;ve added a one liner to Jack&#8217;s DomQuery to make it work as a standalone file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">typeof</span> Ext <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">var</span> Ext <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you want to read more about DomQuery, you can go to <a href="http://www.jackslocum.com/blog/2007/01/11/domquery-css-selector-basic-xpath-implementation-with-benchmarks/">Jack&#8217;s site all about syntax and benchmarks</a>.</p>
<p>Download: <a href="/Projects/Y2/DomQuery.js">Jack Slocum&#8217;s DomQuery Standalone File (24 KB)</a> 1.0 Alpha 3 &#8211; Rev 4<br />
Download: <a href="/Projects/Y2/DomQuery-packer.js">Jack Slocum&#8217;s DomQuery Standalone File Packed (7 KB)</a> 1.0 Alpha 3 &#8211; Rev 4</p>
<p>If you want to use jQuery&#8217;s selector engine, I&#8217;ve stripped out the functions unnecessary to the selector engine in the 1.1.3.1 release and packaged it up as jDomQuery.  There are differences between these two package&#8217;s syntax, so make sure you keep that in mind, especially when looking at the pseudos, like :gt() and :lt() for example.</p>
<p>Download: <a href="/Projects/Y2/jdomquery-1.1.3.1.js">jDomQuery Standalone File (23 KB)</a> 1.1.3.1<br />
Download: <a href="/Projects/Y2/jdomquery-1.1.3.1-packer.js">jDomQuery Standalone File Packed (10 KB)</a> 1.1.3.1</p>
<p>If you want to read about jQuery syntax, <a href="http://docs.jquery.com/Selectors">go over to their documentation</a>.  My current preference is the jQuery syntax, given that it <a href="http://www.zachleat.com/web/2007/07/10/javascript-frameworks-and-jsf/">works with poorly implemented JSF ID attributes</a>.  But that&#8217;s a different argument.</p>
<p>If you want to use the full jQuery library, that should work too, but if you want to do that, you might just want to switch to using jQuery at that point (dare I say it).</p>
<p>Next, we&#8217;ll extend the YAHOO.util.Dom class into a new Y2 namespace.  This will map all of the functions from YAHOO.util.Dom into a new CSS Selector extension.</p>
<h1>Download: <a href="/Projects/Y2/Dom.js">Y2.util.Dom (2 KB)</a></h1>
<p>(pack at your own leisure, you can do it online at <a href="http://dean.edwards.name/packer/">Dean Edward&#8217;s Packer</a>)</p>
<h1>Putting It All Together</h1>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
	&lt;body&gt;
		&lt;div&gt;
			&lt;div class=&quot;first&quot;&gt;
				&lt;span&gt;&lt;/span&gt;
			&lt;/div&gt;
			&lt;div class=&quot;second&quot;&gt;
				&lt;b&gt;&lt;/b&gt;
			&lt;/div&gt;
		&lt;/div&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;/Lib/yui/build/yahoo-dom-event/yahoo-dom-event.js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;jdomquery-1.1.3.1-packer.js&quot;&gt;&lt;/script&gt;
		&lt;!-- &lt;script type=&quot;text/javascript&quot; src=&quot;DomQuery-packer.js&quot;&gt; --&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;Dom.js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;
		Y2.util.Dom.addClass( 'div div:last', 'myClass' )
		Y2.util.Dom.hasClass( 'div div:last', 'myClass' ); // returns true
		var b = Y2.util.Dom.get( 'div div:last b' );
		Y2.util.Dom.addClass( b, 'myOtherClass' );
		&lt;/script&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>One important thing to note is that when using the CSS Selector syntax, when only one node is selected, functions will return a scalar instead of an array.  So if you&#8217;re expecting to select multiple nodes in your selector query and only one node results, make sure your code handling the result is prepared for such an instance.</p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/using-dom-query-libraries-in-yui/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>8 Things the YUI Library Needs to Win Me Back</title>
		<link>http://www.zachleat.com/web/8-things-the-yui-library-needs-to-win-me-back/</link>
		<comments>http://www.zachleat.com/web/8-things-the-yui-library-needs-to-win-me-back/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 05:09:06 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/07/24/8-things-the-yui-library-needs-to-win-me-back/</guid>
		<description><![CDATA[I&#8217;ve been cheating on my first love. When I first started seriously JavaScripting and not CopyPasteScripting, my first framework was the Yahoo User Interface Library. I was just beginning to realize the power of a JavaScript framework, but at the time I also thought that the Dom was an actor in Hollywood&#8217;s The Cannonball Run. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been cheating on my first love.  When I first started seriously JavaScripting and not CopyPasteScripting, my first framework was the Yahoo User Interface Library.  I was just beginning to realize the power of a JavaScript framework, but at the time I also thought that the Dom was an actor in Hollywood&#8217;s <a href="http://www.domdeluise.com">The Cannonball Run</a>.  Hey, everyone&#8217;s gotta get their start somewhere.</p>
<p><img src='http://www.zachleat.com/web/wp-content/uploads/2007/07/dom.jpg' alt='Dom' /></p>
<p>But now I&#8217;ve been learning advanced JavaScripting techniques.  I&#8217;m not a bad person&#8230; but I&#8217;ve been experimenting with new frameworks while YUI was out of town on business.  And ever since I&#8217;ve been going behind YUI&#8217;s back, I&#8217;ve been feeling guilty because it feels so good to cheat.  I am experiencing all these new JavaScript programming ideas that I&#8217;ve never felt before.  But at the same time, I feel regret.  We are still friends and I still hang out with YUI often, but I know she wants me back full time.  I am open to that possibility, but first I want her to change a few things.</p>
<ol>
<li>CSS Selector Engine:  All the major frameworks are doing it.  cssQuery started it (I think?).  jQuery was built on it.  Ext revolutionized it.  Even Mootools, Prototype, and Dojo have their own implementations.  Where is my baby?</li>
<li>An <strong>official</strong> community driven plug-in system: No, I&#8217;m not talking about <a href="http://yazaar.org/">yazaar.org</a>, although it is a good idea.  I want something official, to give credibility to plug-in contributors.  You can still have control of your main components, but why not open it up?</li>
<li>An iterator?  I&#8217;m of course talking about the each() function in jQuery, which operates on both Array&#8217;s and Object&#8217;s without discretion.</li>
<li>Easier Databinding.  Why do I have to program my own logic to iterate through the XML returned in my Ajax call?  At least something that allows me to query an XML document easier (see CSS Selector Engine)</li>
<li>I know I probably shouldn&#8217;t be talking about the component controls, since those are really ancillary to the framework, but a DataTable that supports both horizontal and vertical scrolling while always showing the headers!</li>
<li>Form Validation Utility, or at least a few convenience functions to deal with forms, especially radios and checkboxes.</li>
<li>Of course, I would have said easier operations on HTMLElement&#8217;s, but the new YUI Element (Beta) Utility is doing wonders there.  But how about some sort of DOM Creation class?  Of course, I couldn&#8217;t mention this without plugging the DOM Creation class I built for YUI called <a href="http://www.zachleat.com/web/2007/07/07/domdom-easy-dom-element-creation/">DOMDom</a>.</li>
<li>Client Browser Detection.  While I would never encourage sniffing glue, sometimes sniffing the browser is unavoidable.  This would be a nice convenience when porting plug-in code from other libraries as well.</li>
</ol>
<p>Some might say Chaining, one of jQuery&#8217;s biggest features or a la Dustin Diaz&#8217;s extension to YUI called DED|Chain.  But to be quite honest, that doesn&#8217;t bother me too much.  Chaining might increase convenience a little bit, but perhaps at the sacrifice of a small amount of code readability.  Either way, it isn&#8217;t necessary to me.</p>
<p>So, there you have it.  YUI, you will always have a piece of my heart.  But for now, you only have a piece.  Do you want me back or not?</p>
<p>I&#8217;ll go over what I&#8217;m looking for in the new library I&#8217;ve been eyeing in a future article I&#8217;m tentatively calling &#8220;X Things jQuery Needs to Win Me Over.&#8221;  Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/8-things-the-yui-library-needs-to-win-me-back/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>DOMDom, easy DOM Element Creation</title>
		<link>http://www.zachleat.com/web/domdom-easy-dom-element-creation/</link>
		<comments>http://www.zachleat.com/web/domdom-easy-dom-element-creation/#comments</comments>
		<pubDate>Sun, 08 Jul 2007 04:59:31 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[CSS Selectors]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/07/07/domdom-easy-dom-element-creation/</guid>
		<description><![CDATA[Generally when approaching a complex problem involving web programming in JavaScript, the first question I ask myself is &#8216;What would Jesus do?&#8217; As much as I am entertained by a mental picture of Mr. Jesus himself sitting on his Jesux Distro appending children (and parents) into his DOM, I am instead distracted by an intense [...]]]></description>
			<content:encoded><![CDATA[<p>Generally when approaching a complex problem involving web programming in JavaScript, the first question I ask myself is &#8216;What would Jesus do?&#8217;  As much as I am entertained by a mental picture of Mr. Jesus himself sitting on his <a href="http://www.geocities.com/ResearchTriangle/Node/4081/">Jesux Distro</a> appending children (and parents) into his DOM, I am instead distracted by an intense &#8220;passionate&#8221; hatred for Mel Gibson swelling in my chest.  It&#8217;s actually quite distracting to the problem I am having, but I calm myself by punching my 4 foot tall inflatable Mad Max and wonder how much time I waste doing this.  I figure it happens about twice an hour.  (Digression)</p>
<p>The DOM.  Arch-nemesis of web developers attempting to support the ultimately tiny (I think it&#8217;s down to about 5 or 8% now?) sliver of browser market share that Internet Explorer currently entails.  Let&#8217;s make it easier on ourselves and make a little package to do it for us.  Run a function, pass in an argument with a description of the DOM node(s) we wish to create, and have the package auto-correct any bugs we would have encountered during manual creation, and maybe even have it inserted or appended for us.</p>
<p>But wait, why are we doing this when there are literally 80 billion other DOM element creation classes already out there?  It&#8217;s all about syntax.  The existing packages are incredibly verbose, focusing too much on a complex object structure to describe the nodes, in some cases even having separate objects for attributes inside a single node.  Why not use the syntax we&#8217;ve already come to love in the various DOM query libraries that are available?  Why not use DOMDom? Let&#8217;s see a few examples:</p>
<p>Single Node String</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div&gt;&lt;/div&gt;</pre></div></div>

<p>Single Node String with ID and Classes</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div#id1.class1.class2'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;id1&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;class1 class2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Single Node String for a Form Element</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'input[name=&quot;myTextBox&quot;,type=&quot;text&quot;,maxlength=&quot;5&quot;]'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myTextBox&quot;</span> <span style="color: #000066;">maxlength</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Single Node String with Style Syntax</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div{height=80px,color=#f90,border=1px solid #000}'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;border: 1px solid #000; height: 80px; color: #f90&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Complex Single Node String with ID, multiple classes, Style, and Namespaced Attribute)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div#id1.class1.class2[style=&quot;width:60px;color:#f90&quot;,@class=&quot;class4&quot;,@att=&quot;true&quot;,@namespace:att=&quot;false&quot;]'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;id1&quot;</span> <span style="color: #000066;">att</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">namespace:att</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;class1 class2 class4&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;width: 60px; color: #f90;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Multiple Node String: Linear (Parents with one Child)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div span div'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Multiple Node String: Non-Linear (Parent with more than one Child)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'span'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'span'</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h1>How Does It Work?</h1>
<p>By default, it&#8217;s set up to do HTML Fragments (innerHTML) because they are much speedier than the manual DOM element creation (createElement).  But if you desire, you can toggle a boolean in the code and it will switch back to DOM element creation.  When in DOM element creation mode, it will account for the following browser bugs:</p>
<ul>
<li>(IE6) Standardized for attribute representation (pointer to htmlFor)</li>
<li>(IE6) Standardized case for accesskey, usemap, maxlength, and frameborder attributes.</li>
<li>(IE6) Standardized checked attribute for radio and checkboxes.</li>
<li>(IE6) Special consideration for dynamic handling of name and type attributes (on form elements).</li>
<li>(Firefox) <a href="http://developer.mozilla.org/en/docs/Whitespace_in_the_DOM">Works with whitespace that is treated as a node.</a></li>
</ul>
<h1>Syntax</h1>
<p>You should already be able to tell how to create a node from the examples above.  Here are some more things you might not have guessed:</p>
<p>Creating a node with an id</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div#myId'</span></pre></div></div>

<p>Creating a node with CSS classes</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div.class1.class2'</span></pre></div></div>

<p>Creating two nodes at the same level</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'div'</span> <span style="color: #009900;">&#93;</span></pre></div></div>

<p>Creating a node with two children</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'div'</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can mix the {} and [] syntax wherever you like, but if you want a node to have non-linear children, you have to use the {} object notation.</p>
<p>Creating a text node (start the node declaration with a #, you can change this to another non-conflicting character in the code if you like)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'#Any Text Here'</span></pre></div></div>

<p>Creating a node with attributes (the @ is optional)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div[class=&quot;class3&quot;,style=&quot;width:60px;color:#f90&quot;,@att=&quot;true&quot;,@namespace:att=&quot;false&quot;]'</span></pre></div></div>

<p>Creating a node with a Style Shortcut (mixing with a style attribute is handled properly)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div{color=#f90,border=1px solid #000}[style=&quot;height:80px;background:#fff&quot;]'</span></pre></div></div>

<p>A few notes on attributes.  Quotes are required on attributes (single or double but be consistent), but are not required in the style shortcut declaration.  Quotes are not allowed to be nested inside of attributes (a single quote cannot be inside of a double quote and vice versa).</p>
<p>And of course, all of the above can be mixed together</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">'div#myId.class1.class2{color=#f90}[customAttr=&quot;true&quot;,@customAttr2=&quot;false&quot;] div#child1 div#child2'</span></pre></div></div>

<h1>Usage</h1>
<p><strong>Appending</strong> at the end of a parent&#8217;s children:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">DOMDom.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> yourParentNode <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Replacing</strong> the children of a parent:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">DOMDom.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> yourParentNode <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Unshifting </strong>(inserting at the beginning of a parent&#8217;s children):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">DOMDom.<span style="color: #660066;">unshift</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> yourParentNode <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Inserting</strong> before a certain integer index of a parent&#8217;s children:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">DOMDom.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> yourParentNode<span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// must have at least 3 children, the index is 0 based, if index is null with unshift by default</span></pre></div></div>

<h1>Templates</h1>
<p>Use &lt;$var&gt; to indicate a variable, in this example &lt;$test&gt;</p>
<p><code><br />
// "Compile" the template<br />
var str = DOMDom.compile( { 'div.test span': '#Test &lt;$test&gt;' } );</p>
<p>// Use your template in some context, notice the test variable being set.<br />
for( var j = 0; j < 1000; j++ )<br />
{<br />
	// knows we're using a compiled template since we're passing in variables as a third argument.<br />
	DOMDom.append( str, d, { test: j } );<br />
}<br />
</code></p>
<h3>Benchmarks</p>
<h4>
(If you have Firebug open, make sure it's not on the HTML tab, this will slow down the benchmark significantly)</p>
<p>Most of my work here has been inspired by the DomQuery and DomHelper classes written by JavaScript rock star Jack Slocum (the guy's initials are J.S. for God's sake), so I modeled my benchmark after <a href="http://www.jackslocum.com/blog/examples/domhelper.php">his benchmark hosted on his website to test the DomHelper class</a>.  I'm running the same nodes he's testing on his website, so the results should be comparable.  You can <a href="http://www.zachleat.com/Projects/DOMDom/benchmark.html">test my benchmark for DOMDom here</a>.  Here are some results, reporting the average of 3 results with the format of an uncompiled element first and the compiled template in square brackets.<br />
</h4>
<h2>DOMDom Results</h2>
<p>Internet Explorer 6: 666 ms [328 ms]<br />
Firefox 2.0.0.4: 1880 ms [666 ms]<br />
Safari 3.0.2 [Windows]: 546 ms [151 ms]<br />
Opera 9.21: 343 ms [140 ms]</p>
<h2>Comparative numbers from Jack Slocum's DomHelper</h2>
<p>Internet Explorer 6: 2458 ms [677 ms]<br />
Firefox 2.0.0.4: 672 ms [458 ms]<br />
Safari 3.0.2 [Windows]: 291 ms [119 ms]<br />
Opera 9.21: 370 ms [166 ms]</p>
<p>The thing to take away from this is the question of why Satan is haunting my benchmarks?  Two 666 averages?  Anyway, DOMDom is quite a bit faster in the most popular browser, Internet Explorer, although I haven't tested it on IE7 yet.  In Firefox, the opposite is true, with DomHelper taking the lead.  Opera is comparable and Safari is faster in DomHelper as well.  You can run your own tests using the links above.</p>
<h1>Dependencies</h1>
<p>This library was built to work with Yahoo User Interface (YUI), but could be trivially ported to another library by changing the function dependencies listed in the ADAPTER variable in the code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> ADAPTER <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	setStyle<span style="color: #339933;">:</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">setStyle</span><span style="color: #339933;">,</span>
	addClass<span style="color: #339933;">:</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #339933;">,</span>
	isString<span style="color: #339933;">:</span> YAHOO.<span style="color: #660066;">lang</span>.<span style="color: #660066;">isString</span><span style="color: #339933;">,</span>
	isArray<span style="color: #339933;">:</span> YAHOO.<span style="color: #660066;">lang</span>.<span style="color: #660066;">isArray</span><span style="color: #339933;">,</span>
	isNumber<span style="color: #339933;">:</span> YAHOO.<span style="color: #660066;">lang</span>.<span style="color: #660066;">isNumber</span><span style="color: #339933;">,</span>
	isObject<span style="color: #339933;">:</span> YAHOO.<span style="color: #660066;">lang</span>.<span style="color: #660066;">isObject</span><span style="color: #339933;">,</span>
	get<span style="color: #339933;">:</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">get</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// to port, change these references</span></pre></div></div>

<p>If you're still reading this encyclopedia, here are some links:</p>
<ul>
<li><span style="font-size: 200%"><a href="http://www.zachleat.com/Projects/DOMDom/DOMDom.js">DOWNLOAD DOMDom</a></span></li>
<li><a href="http://www.zachleat.com/Projects/DOMDom/DOMDom-min-jsmin.js">DOWNLOAD DOMDom Minimized with JSMIN (10KB)</a></li>
<li><a href="http://www.zachleat.com/Projects/DOMDom/DOMDom-min-packer.js">DOWNLOAD DOMDom Minimized with Packer (6KB)</a></li>
<li><a href="http://www.zachleat.com/Projects/DOMDom/benchmark.html">See the benchmark</a></li>
<li><a href="http://www.zachleat.com/Projects/DOMDom/tests.html">See the test file with a bunch of examples of syntax</a></li>
</ul>
<p><a href="http://www.encyclopedia.com/doc/1O27-dom1.html"><em>-dom suffix denoting condition or state, as in freedom, wisdom, or DOMDom</em></a></p>
<p><strong>Update</strong>: changed the variable syntax to allow variables inside of nodes (not just text).</h3>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/domdom-easy-dom-element-creation/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Wake up to YouTube on my Internet Alarm Clock</title>
		<link>http://www.zachleat.com/web/wake-up-to-youtube-on-my-internet-alarm-clock/</link>
		<comments>http://www.zachleat.com/web/wake-up-to-youtube-on-my-internet-alarm-clock/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 01:40:07 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[Interface Design]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Alarmd]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/06/18/wake-up-to-youtube-on-my-internet-alarm-clock/</guid>
		<description><![CDATA[Update: Try the new ALARMd 2 Beta, with Google Calendar integration and offline Youtube caching. Did you take your contacts out last night and you can&#8217;t see the time on your alarm clock from all the way across the room? I&#8217;m here to calm your fears. Enter ALARMD, the Internet Alarm Clock. Wake up to [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update</strong>: Try the new <a href="http://www.zachleat.com/web/2008/04/06/alarmd-2-beta-with-google-calendar-integration/">ALARMd 2 Beta</a>, with Google Calendar integration and offline Youtube caching.</em></p>
<p>Did you take your contacts out last night and you can&#8217;t see the time on your alarm clock from all the way across the room?  </p>
<p>I&#8217;m here to calm your fears.  Enter <a href="http://www.zachleat.com/Projects/alarmd/">ALARMD, the Internet Alarm Clock</a>.  Wake up to any Youtube video (that allows embedding), a last.fm user stream or tag, or any mp3 hosted online.  There are a few defaults in there, but you can add and modify your own.</p>
<p><a href="http://www.flickr.com/photos/zachleat/531165035/" title="Photo Sharing"><img src="http://farm2.static.flickr.com/1067/531165035_d2ba407333.jpg" width="500" height="375" alt="Now that's an alarm clock" /></a></p>
<p>Features:</p>
<ul>
<li>Supports multiple alarms (ALT+R to add an alarm or use the Add Alarm button).</li>
<li>Options for 24 Hour (Military) time and Seconds display</li>
<li>Supports MP3 (hosted online), YouTube videos (that allow embedding), and last.fm user or tag streams.</li>
<li>Key Mash Mode to kill the alarm (hit five random keys in one second)</li>
<li>Time Font Size customization (automatically size to the width of the window using the Max option)</li>
<li>Typical alarm clock colors: Red, Green, or Blue</li>
<li>Alarm Toggle based on the Day of the Week</li>
<li>Test button to make sure your speaker volume is set correctly.</li>
<li>Sleep Mode button to get rid of the extra GUI while you don&#8217;t need it.</li>
<li>Save all of your settings, URL&#8217;s, and alarms locally in a cookie (you <strong>don&#8217;t</strong> need yet another account to use this)</li>
</ul>
<p>Things to think about:</p>
<ul>
<li>Power Settings &#8211; disable your screen saver, or any sort of automatic suspend or sleep setting.  In my testing, having your monitor go into power save mode is acceptable, and the alarms will still sound (but you might want to test this yourself and leave a comment with your result).</li>
<li>You might not want to use with a CRT, for fear of burn in.</li>
<li>Personally, I like to use this in Opera, just because their default full screen mode (F11) doesn&#8217;t have toolbars or a status bar.  But you can use the <a href="https://addons.mozilla.org/en-US/firefox/addon/4650">Fuller Screen Firefox plug-in</a> to soup up your Firefox for similar functionality.</li>
<li>Word of warning, the window <strong>must</strong> have focus to autoplay YouTube videos.</li>
<li>Make sure your local time on your computer is correct, especially if you are traveling between time zones.  It doesn&#8217;t do any server side validation on the time (yet?).</li>
</ul>
<p>Possible Future Improvements:</p>
<ul>
<li>Countdown mode, displays amount of time until next alarm in place of the clock (good for timed presentations, where you want to see how much time is left before you have to quit).</li>
<li>Google Gears integration for offline mode (if your internet goes out during the night)</li>
<li>Support customizing source URL&#8217;s on a per alarm basis.</li>
<li>Support days of the week toggle on a per alarm basis.</li>
<li>Support user specified color customization.</li>
<li>A crescendo alarm MP3 that increases in volume for a more peaceful wake up experience.</li>
<li>An alarm MP3 with especially violent noises for heavy sleepers.</li>
<li>An alarm MP3 of my mom&#8217;s voice to get that nice feeling of childhood back.</li>
</ul>
<p>This internet application was built using the Yahoo UI Libraries (YUI) and Jack Slocum&#8217;s Ext DomQuery class.  It is written entirely without using any server side programming languages, and therefore can be saved to your local machine.  Not that anyone might want to use the Internet Alarm Clock, but if you do, I declare it officially released under the BSD license.  Just don&#8217;t forget to cite the source when you redistribute.</p>
<p><strong>Update</strong>: added a couple more things to think about.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/wake-up-to-youtube-on-my-internet-alarm-clock/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Enlarging your YUI DataTable in 30 Seconds or Less!</title>
		<link>http://www.zachleat.com/web/enlarging-your-yui-datatable-in-30-seconds-or-less/</link>
		<comments>http://www.zachleat.com/web/enlarging-your-yui-datatable-in-30-seconds-or-less/#comments</comments>
		<pubDate>Fri, 08 Jun 2007 02:51:08 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Interface Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Expandable]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/06/07/enlarging-your-yui-datatable-in-30-seconds-or-less/</guid>
		<description><![CDATA[Please note that this post has been updated to the new version of YUI, 2.3.0 in an article called &#8220;Enlarging your YUI DataTable in 29 Seconds or Less!&#8221; Do you want to fit more content onto your DataTable, but don&#8217;t know how? Do you wish that you had fewer columns, or more horizontal screen-estate? Well [...]]]></description>
			<content:encoded><![CDATA[<p><b>Please note that this post has been updated to the new version of YUI, 2.3.0 in an article called <a href="http://www.zachleat.com/web/2007/08/28/enlarging-your-yui-datatable-in-29-seconds-or-less/">&#8220;Enlarging your YUI DataTable in 29 Seconds or Less!&#8221;</a></b></p>
<p>Do you want to fit more content onto your DataTable, but don&#8217;t know how?  Do you wish that you had fewer columns, or more horizontal screen-estate?  Well now you can enlarge your table easily with these simple functions!  Instead of adding more information into additional columns, we have used our patented method of not actually patenting anything to bring you a secret formula that will allow you to dynamically insert rows into your table, designed for holding additional, non-constrained customizable content!</p>
<p>Do you mean to tell me that your formula will give that special lady in your life the DataTable that she has always wanted?</p>
<p>Of course!  In fact, we guarantee this DataTable to satisfy all of the women you know and don&#8217;t know in the world or we&#8217;ll give you a full refund of the purchase price!</p>
<p>Wow! How does it work?</p>
<p><a href="http://www.zachleat.com/Projects/valdi/__test_yui_datatable_expandable.html"></p>
<p>Click here for an example!</p>
<p><img src='http://www.zachleat.com/web/wp-content/uploads/2007/06/datatable.gif' alt='Normal DataTable' /></p>
<p><img src='http://www.zachleat.com/web/wp-content/uploads/2007/06/datatableexpanded.gif' alt='Expanded DataTable' /><br />
</a></p>
<p>When you click on a row in the DataTable, it inserts a child row beneath the row with an HTML string passed in to populate the dynamic content.  When you click on the parent row or the new row that was inserted, the content disappears!  It&#8217;s that easy!  You don&#8217;t have to apply any gross awful smelling creams, or take any large horse-sized pills for this to work!  You literally only use the following code to do it:</p>
<p>Usage Code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myDataTable <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> YAHOO.<span style="color: #660066;">widget</span>.<span style="color: #660066;">DataTable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;myContainer&quot;</span><span style="color: #339933;">,</span>myColumnSet<span style="color: #339933;">,</span>myDataSource<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
myDataTable.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;cellClickEvent&quot;</span><span style="color: #339933;">,</span> myDataTable.<span style="color: #660066;">onEventSelectRow</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// make sure you're firing the row selection event</span>
myDataTable.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;cellClickEvent&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> myCustomHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Hello, this is my expanded content.&lt;br /&gt;:-)&lt;br /&gt;'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// generate the string, could use an ajax call if you wanted.</span>
   YAHOO.<span style="color: #660066;">ymod</span>.<span style="color: #660066;">datatable</span>.<span style="color: #660066;">clickAndExpand</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> e<span style="color: #339933;">,</span> myCustomHtml <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// if you do use an ajax call, this function returns a reference to the newly created div that you can put the ajax results into.</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Library Code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'YAHOO.ymod.datatable'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
YAHOO.<span style="color: #660066;">ymod</span>.<span style="color: #660066;">datatable</span>.<span style="color: #660066;">clickAndExpand</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e<span style="color: #339933;">,</span> expandedHtml <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> selectedRows <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getSelectedRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> selectedRows.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'ymod-expandedData'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">previousSibling</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'expanded'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'ymod-expanded'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> newRow <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'tr'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> newCell <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'td'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> newDiv <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'div'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> newDiv<span style="color: #339933;">,</span> <span style="color: #3366CC;">'ymod-expandedDataContent'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> expandedHtml <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> newDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> expandedHtml<span style="color: #339933;">;</span>
			newCell.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span> newDiv <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			newCell.<span style="color: #660066;">colSpan</span> <span style="color: #339933;">=</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
			newRow.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span> newCell <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> newRow<span style="color: #339933;">,</span> <span style="color: #3366CC;">'ymod-expandedData'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'yui-dt-odd'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> newRow<span style="color: #339933;">,</span> <span style="color: #3366CC;">'yui-dt-odd'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'yui-dt-even'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> newRow<span style="color: #339933;">,</span> <span style="color: #3366CC;">'yui-dt-even'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'ymod-expanded'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span> newRow<span style="color: #339933;">,</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nextSibling</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> newRow<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				YAHOO.<span style="color: #660066;">ymod</span>.<span style="color: #660066;">datatable</span>.<span style="color: #660066;">collapseRow</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">stopEvent</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'yui-dt-selected'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">stopEvent</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> newDiv<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nextSibling</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'ymod-expanded'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> selectedRows<span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'yui-dt-selected'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">stopEvent</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// pass in the expanded content, NOT the parent row.</span>
YAHOO.<span style="color: #660066;">ymod</span>.<span style="color: #660066;">datatable</span>.<span style="color: #660066;">collapseRow</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> row <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> row.<span style="color: #660066;">previousSibling</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'ymod-expanded'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> row.<span style="color: #660066;">previousSibling</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'yui-dt-selected'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	row.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span> row <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Customize the CSS, if desired.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.yui-dt-table</span> tr<span style="color: #6666ff;">.ymod-expandedData</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#bdcede</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> tr<span style="color: #6666ff;">.ymod-expandedData</span> td <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">visible</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> tr.ymod-<span style="color: #993333;">expanded</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#bdcede</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> tr.ymod-<span style="color: #993333;">expanded</span> td <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> div<span style="color: #6666ff;">.ymod-expandedDataContent</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f4f4f4</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">inset</span> <span style="color: #cc00cc;">#aaa</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> zoom<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You might even want to put a little + and &#8211; into the first column of each row to give a visual cue that there is more information for display available on click.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/enlarging-your-yui-datatable-in-30-seconds-or-less/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Wash your mouth out with SOAP and the YUI Connection Manager</title>
		<link>http://www.zachleat.com/web/wash-your-mouth-out-with-soap-and-the-yui-connection-manager/</link>
		<comments>http://www.zachleat.com/web/wash-your-mouth-out-with-soap-and-the-yui-connection-manager/#comments</comments>
		<pubDate>Wed, 09 May 2007 22:56:58 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/05/09/wash-your-mouth-out-with-soap-and-the-yui-connection-manager/</guid>
		<description><![CDATA[Now you&#8217;ve done it. You watched an R rated movie while your parents weren&#8217;t looking and used some of your newfound acquired colorful language in front of them. Your mom goes for the Dial Liquid Soap, she&#8217;s going to wash that profanity right out of your dirty little mouth. Harsh? Maybe, but I couldn&#8217;t say [...]]]></description>
			<content:encoded><![CDATA[<p>Now you&#8217;ve done it.  You watched an R rated movie while your parents weren&#8217;t looking and used some of your newfound acquired colorful language in front of them.  Your mom goes for the Dial Liquid Soap, she&#8217;s going to wash that profanity right out of your dirty little mouth.</p>
<p>Harsh?  Maybe, but I couldn&#8217;t say the word &#8216;Bastards&#8217; without feeling Dial on my cleansed taste buds.  Maybe I should take legal action against the cinematic classic &#8216;<a href="http://www.imdb.com/title/tt0102059/">Hot Shots</a>.&#8217;</p>
<p>What are we here for?  Not liquid soap, perhaps some profanity.  But really, you want to use the SOAP web services protocol with your Yahoo User Interface application, in particular the Connection Manager component.  This tutorial assumes you are at least familiar with <a href="http://developer.yahoo.com/yui/connection/">the examples provided on the Yahoo! UI Library: Connection Manager website</a>.</p>
<p>How is SOAP different than any other AJAX call using the Connection Manager?  Well, normally, when you perform an HTTP Post AJAX call, it is passing in a key-value pair string encoded with the normal key=value&#038;key2=value format.  But when doing a SOAP call, we want to post an XML SOAP Envelope to the server instead of this key-value pair string.  In case you&#8217;re reading this article and don&#8217;t know what a SOAP Envelope looks like, I&#8217;ll post a sample here:<br />
<code><br />
&lt;s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"&gt;<br />
&lt;s11:Header&gt;<br />
&lt;/s11:Header&gt;<br />
&lt;s11:Body&gt;<br />
&lt;/s11:Body&gt;<br />
&lt;/s11:Envelope&gt;<br />
</code></p>
<p>Of course, it is beyond the scope of this article to argue whether a REST or a SOAP format for your Service Oriented Architecture is a better choice.  You&#8217;re stuck with SOAP, otherwise you wouldn&#8217;t have read this far.</p>
<p>So, let&#8217;s post our SOAP Envelope using the YUI Connection Manager with the code provided below:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> targetUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://www.zachleat.com/postToServer.php'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// this is not a real URL</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> callback <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> root <span style="color: #339933;">=</span> o.<span style="color: #660066;">responseXML</span>.<span style="color: #660066;">documentElement</span><span style="color: #339933;">;</span> 
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> root.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'faultstring'</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// faultstring is a standard SOAP error message format</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> faultstring <span style="color: #339933;">=</span> root.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'faultstring'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> detailed <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
			YAHOO.<span style="color: #660066;">UP</span>.<span style="color: #660066;">util</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> root.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'detail'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> j<span style="color: #339933;">,</span> textNode <span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> textNode.<span style="color: #660066;">nodeValue</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> detailed <span style="color: #339933;">+=</span> textNode.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// do something with your error message stored in the faultstring variable, with a more detailed message in the detailed variable</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// this is an actual success.</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
	failure<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> o <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// do something with your failure.</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> message <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;s11:Envelope...YOUR SOAP MESSAGE HERE'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// we need to set our own header.</span>
YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Connect</span>._use_default_post_header <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Connect</span>.<span style="color: #660066;">initHeader</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Content-Type'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'text/xml'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> ajaxCall <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Connect</span>.<span style="color: #660066;">asyncRequest</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> targetUrl<span style="color: #339933;">,</span> callback<span style="color: #339933;">,</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I hope this code helps some of you bastards.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/wash-your-mouth-out-with-soap-and-the-yui-connection-manager/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>YUI DataTable and You: Making the Marriage Work</title>
		<link>http://www.zachleat.com/web/yui-datatable-and-you-making-the-marriage-work/</link>
		<comments>http://www.zachleat.com/web/yui-datatable-and-you-making-the-marriage-work/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 22:48:09 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/04/30/yui-datatable-and-you-making-the-marriage-work/</guid>
		<description><![CDATA[The DataTable/Grid Component, the ball and chain of GUI components. It doesn&#8217;t let you go out and instantiate beers to create a inebriated subclass of yourself with your friends on Friday night. It makes you do household garbage collection during the last minute of your favorite sporting event. And you&#8217;d think it would die before [...]]]></description>
			<content:encoded><![CDATA[<p>The DataTable/Grid Component, the ball and chain of GUI components.  It doesn&#8217;t let you go out and instantiate beers to create a inebriated subclass of yourself with your friends on Friday night.  It makes you do household garbage collection during the last minute of your favorite sporting event.  And you&#8217;d think it would die before it would ever encapsulate your private class member.  Just to warn you, the previous sentence was not safe for work.</p>
<p>Earlier I published an article entitled <a href="/web/2007/04/04/problems-with-yui-datatable/">Problems with the YUI DataTable</a>.  Now we&#8217;re going to work out those problems together, through better communication and more effective problem solving techniques.  We&#8217;re going to save your marriage.</p>
<p>Earlier I had stated that there were a few problems with the DataTable, in its current form.  Let&#8217;s review (but not play the blame game).</p>
<ul>
<li>Bug #1: Table headers weren&#8217;t lining up correctly in Firefox (personal ignorance on Box Models)</li>
<li>Bug #2: Single Select bug where multiple rows were being selected when column was sorted (All browsers, Sortable and SingleSelect Tables)</li>
<li>Bug #3: Header displayed out of document flow when the window was resized (IE6, Scrollable Tables)</li>
<li>Bug #4: Content was being displayed approximately 60-70 pixels inside the bottom table boundary. (Firefox, Scrollable Tables) Note the position of the &#8216;Top&#8217; links in the test document below.</li>
<li>Bug #5: More of a limitation than a bug, the DataTable does not allow a fixed width table with horizontal overflow.  Say you have a table that you have fixed column widths for, but if the width of the real estate available for the table is less than this minimum, the table should overflow with a scroll bar, but at the same time showing the column headers if you scroll vertically.  A picture is better:<br />
<img src='/web/wp-content/uploads/2007/04/yui-datatable1.gif' alt='Scrollable' /></li>
</ul>
<p>See the following <a href="http://www.zachleat.com/Projects/valdi/__test_yui_datatable_original.html">test document</a> for relevant table tests. (Note that for the purposes of testing, I&#8217;ve decided to test all combinations of the Top 3 DataTable features: scrolling, nested table headers, and sorting)</p>
<p>Just like your favorite professor, now I&#8217;m going to post the <strong>Solutions</strong>:</p>
<p>Bug #1: What is your Box Model?</p>
<p>Use the following JavaScript code to tell if you&#8217;re in Standards Mode or Quirks Mode:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> document.<span style="color: #660066;">compatMode</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'CSS1Compat'</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'Standards Mode'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Quirks Mode'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Standards mode forces your document into using the W3C Box Model, which is currently the standard.  The W3C Box Model means any width declarations you make in your CSS code will not include padding, border, or margins.  So if you put padding on your table cells and headers, it will need <em>to be added on separately to the total width of your table</em>.</p>
<p>Bug #2: Someone has posted the solution on the <a href="http://sourceforge.net/tracker/index.php?func=detail&#038;aid=1701632&#038;group_id=165715&#038;atid=836476">Sourceforge Bug Tracker here</a>.  (This is included in the DataTable javascript file below)</p>
<p>Bug #3, #4, and #5: I have produced an alternate DataTable file that fixes these bugs using JavaScript code.  All lines that were added or changed are commented with //ADDED or //CHANGED</p>
<p>Developed in and last tested with YUI version 2.2.2.</p>
<p>Download it here:<br />
Full (169 KB): <a href='http://www.zachleat.com/web/wp-content/uploads/2007/04/ymod-datatable-beta.js' title='ymod-datatable-beta.js'>ymod-datatable-beta.js</a><br />
Minimized using <a href="http://www.crockford.com/javascript/jsmin.html">JSMIN</a> (67 KB): <a href='http://www.zachleat.com/web/wp-content/uploads/2007/04/ymod-datatable-beta-min.js' title='ymod-datatable-beta-min.js'>ymod-datatable-beta-min.js</a></p>
<p>The original and minimized YUI DataTable files are 166 KB and 66 KB respectively.</p>
<p>See the <a href="/Projects/valdi/__test_yui_datatable_fluid.html">fluid width DataTables in action here</a>.</p>
<p>A few notes on doing a fixed width DataTable using the code provided above.  The total width of the table body must be 16px less than the width of the header, if you have vertical scrolling (to account for the scrollbar).  So, if the total width of your header is 800px, the total width of your body must be 784px (put the last table cell as 16px smaller).</p>
<p>Here&#8217;s the CSS to go along with a horizontal scrolling DataTable:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.yui-dt-table</span> th<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.yui-dt-table</span> td <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> th<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.yui-dt-table</span> tr<span style="color: #6666ff;">.yui-dt-first</span> td <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/* table header and only the first row (for drag and drop) */</span>
<span style="color: #6666ff;">.ymod-scrollingBody</span> <span style="color: #6666ff;">.yui-dt-table</span> tr<span style="color: #6666ff;">.yui-dt-first</span> td<span style="color: #6666ff;">.yui-dt-last</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">84px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/* last table cell (for crappy scrollbar problem) */</span>
<span style="color: #6666ff;">.yui-dt-table</span> <span style="color: #6666ff;">.yui-dt-even</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> <span style="color: #6666ff;">.yui-dt-odd</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#e0dfe0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> <span style="color: #6666ff;">.yui-dt-selected</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#bdcede</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> thead <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#933</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-table</span> th a <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span> ! important<span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.ymod-scrollingHeader</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.ymod-nestedHeaders</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* gotta set this manually, unfortunately */</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.ymod-scrollingHeader</span> table <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.ymod-scrollingBody</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.ymod-scrollingHeader</span> table <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">800px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/* Set your widths! */</span>
<span style="color: #6666ff;">.ymod-scrollingBody</span> table <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">784px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/yui-datatable-and-you-making-the-marriage-work/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Google Using YUI Grids CSS</title>
		<link>http://www.zachleat.com/web/google-using-yui-grids-css/</link>
		<comments>http://www.zachleat.com/web/google-using-yui-grids-css/#comments</comments>
		<pubDate>Thu, 05 Apr 2007 16:33:22 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[CSS Grids]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Licensing]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/04/05/google-using-yui-grids-css/</guid>
		<description><![CDATA[Head over to the Google Homepage. Log In using your Google Account. Make sure you&#8217;re at your Personalized Homepage. Take a look at the source CSS file ig.css included on the page. There are a few peculiar lines of code that I recognized from another source, the Yahoo User Interface Grids CSS file. Yahoo has [...]]]></description>
			<content:encoded><![CDATA[<p>Head over to the <a href="http://www.google.com/ig?hl=en">Google Homepage</a>.  Log In using your Google Account.  Make sure you&#8217;re at your <a href="http://www.google.com/ig?hl=en">Personalized Homepage</a>.  Take a look at the source CSS file <a href="http://www.google.com/ig/f/tB22vfBbv0g/ig.css">ig.css</a> included on the page.  There are a few peculiar lines of code that I recognized from another source, the Yahoo User Interface Grids CSS file.  Yahoo has provided a set of standard CSS definitions under the BSD license that allow a developer to easily make fluid or fixed width column layouts.  And on the Google Personalized Homepage, there are the following class definitions:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#modules</span> <span style="color: #6666ff;">.yui-b</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">static</span><span style="color: #00AA00;">;</span>display<span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>float<span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>overflow<span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-gb</span> <span style="color: #6666ff;">.yui-u</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>margin-<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">2%</span><span style="color: #00AA00;">;*</span><span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.895%</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #933;">32%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-gb</span> div<span style="color: #6666ff;">.first</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#modules</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.yui-gb</span><span style="color: #00AA00;">&#123;</span>zoom<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This code includes identical Class names taken from the <a href="http://developer.yahoo.com/yui/grids/">Yahoo User Interface library Grids CSS</a> component.  Here is the source in the <a href="http://yui.yahooapis.com/2.2.0/build/grids/grids-min.css">grids.css</a> file from Yahoo (truncated for simplicity).</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#yui-main</span> <span style="color: #6666ff;">.yui-b</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">static</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-t7</span> <span style="color: #cc00cc;">#yui-main</span> <span style="color: #6666ff;">.yui-b</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#yui-main</span> <span style="color: #6666ff;">.yui-b</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-gb</span> <span style="color: #6666ff;">.yui-u</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>margin-<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">2%</span><span style="color: #00AA00;">;*</span><span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.895%</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #933;">32%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-gb</span> div<span style="color: #6666ff;">.first</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#bd</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.yui-gb</span><span style="color: #00AA00;">&#123;</span>zoom<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Obviously, it&#8217;s the same code, with a few minor differences.</p>
<p><img src='http://www.zachleat.com/web/wp-content/uploads/2007/04/yuigrids-google1.jpg' alt='Screenshot proof' /></p>
<p>The interesting thing to note is that the YUI Grids CSS source code is licensed under a <a href="http://developer.yahoo.com/yui/license.html">BSD license</a>, which includes the following provisions:</p>
<blockquote><p>Redistributions of source code must retain the above copyright notice, this list of conditions and the<br />
following disclaimer.</p></blockquote>
<p>The copyright notice they&#8217;re referring to is not included anywhere on the Google Personalized Homepage (and would seem to be a violation of the license).  Now this may seem like a small infraction when we&#8217;re just talking about 4 lines of CSS code.  But really, if they think the code is good enough that they will use it in such a prominent way and not write it from scratch using their own means, they should follow the licensing agreements stipulated.</p>
<p><strong>Update</strong><br />
Google has added the BSD license statement and attribution to Yahoo in their CSS file (<a href="http://www.google.com/ig/f/tB22vfBbv0g/ig.css">ig.css</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* ===============BEGIN BSD LICENSED PORTION============= */</span>
<span style="color: #808080; font-style: italic;">/*
Copyright (c) 2007, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.2.0
*/</span>
&nbsp;
<span style="color: #cc00cc;">#modules</span> <span style="color: #6666ff;">.yui-b</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">static</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-gb</span> <span style="color: #6666ff;">.yui-u</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">2%</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.895%</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">32%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-gb</span> div<span style="color: #6666ff;">.first</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#modules</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.yui-gb</span> <span style="color: #00AA00;">&#123;</span>
  zoom<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* ===============END BSD LICENSED PORTION============= */</span></pre></div></div>

<p>Sorry to everyone visiting the page for the extra millisecond or two it will take to load these comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/google-using-yui-grids-css/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Problems with YUI DataTable</title>
		<link>http://www.zachleat.com/web/problems-with-yui-datatable/</link>
		<comments>http://www.zachleat.com/web/problems-with-yui-datatable/#comments</comments>
		<pubDate>Wed, 04 Apr 2007 22:52:41 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Interface Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/04/04/problems-with-yui-datatable/</guid>
		<description><![CDATA[If you have read anything I&#8217;ve written before or know me at all, you know that my go-to JavaScript library is the one and only YUI. So obviously, when I was looking around for a Grid (or as YUI jargon goes, a DataTable), naturally I&#8217;m going to turn to YUI compatible components. First, I looked [...]]]></description>
			<content:encoded><![CDATA[<p>If you have read anything I&#8217;ve written before or know me at all, you know that my go-to JavaScript library is the one and only YUI.  So obviously, when I was looking around for a Grid (or as YUI jargon goes, a DataTable), naturally I&#8217;m going to turn to YUI compatible components.  First, I looked at Jack Slocum&#8217;s EXT, which has a nice looking Grid component that had a lot of features I wouldn&#8217;t need, but I didn&#8217;t really want to take a 0.5 MB hit for the limited feature set I was requiring.  Adding the YUI DataTable would only tack on approximately 70-75 KB of additional download.  So first, let me establish what I&#8217;m going for:</p>
<p><strong>Minimum Feature Set</strong>:</p>
<ul>
<li>Client-Side Sorting: I don&#8217;t want it to do an XMLHttpRequest to sort the data, I want it to be done all clientside.</li>
<li>Simple inline editing: Edit a field in the table right there on the table.  I hadn&#8217;t established what types of data I would need to edit yet.</li>
<li>Data Sources: load from a native JavaScript array or a XMLHttpRequest returning XML or JSON.</li>
<li>Data Type Sort Algorithms: at the very minimum different sorting algorithms for numeric columns and string columns.</li>
<li>Hierarchical Columns: group column headers together under a parent header.</li>
<li>Easily customizable: must be able to customize the look and feel of the grid easily using CSS and not by editing Javascript.</li>
<li>Header Freeze: If I have overflow on my table vertically causing a scroll bar, I want the table headers to remain shown at the top of the table while I scroll from top to bottom.</li>
<li>Custom Cell Rendering: I have the data I&#8217;m loading, but I want to change how it looks when it is rendered to the table.  Common for date formatting.</li>
</ul>
<p><strong>Luxury Feature Set</strong>:</p>
<ul>
<li>Resizeable Columns: change the width of a column by dragging on the column header&#8217;s right border.</li>
<li>Movable Columns: dragging a column will cause it to be moved on the table (TIBCO General Interface supports this).</li>
<li>Custom Sort Algorithm: write my own algorithm to specify how data is sorted, or provide a way to do multi-column sorting (sort within one column, ties are sorted by another column, and so on).</li>
<li>Dynamic Paging (don&#8217;t make me click numbered links, load the data automatically when I scroll) both on the client (dynamically insert only what I&#8217;m looking at and remove what I&#8217;ve scrolled past) and using the server (load more data through an XMLHttpRequest)</li>
<li>Column Freeze: if the table is going to scroll horizontally, allow the developer to freeze a column or multiple columns so that they are shown when scrolling from left to right.</li>
</ul>
<p><strong>Evaluation of Options</strong>: How does the YUI DataTable stack up?</p>
<p>Basic Items: Client-Side Sorting, Simple inline editing, Data Sources, Data Type Sort Algorithms (<em>stock types not yet implemented out of the box</em>), Hierarchical Columns, Header Freeze (<em>buggy</em>), Custom Cell Rendering, and is easily customizable with CSS.</p>
<p>Luxury Items: Resizeable Columns, Movable Columns (<em>not supported</em>), Custom Sort Algorithms are supported (you can right your own Data Type Sort Algorithms with this feature), Dynamic Paging (manually, not dynamic), Column Freeze (<em>not supported</em>)</p>
<p>Problems:</p>
<ul>
<li>Any sort of fixed width table is going to be problematic.  Putting a fixed width on the table causes the table headers to be misaligned with the associated table data.  It&#8217;s a mess.  The only viable option here is to let the table do it&#8217;s own width calculations.  You can&#8217;t even set the column widths manually using the {width} variable as suggested when using a fixed width table.</li>
<li>Data Type Sort Algorithms supposedly work from the column type, but this feature is documented in the code as being a TODO.  All columns are sorted by a string datatype, meaning that if your column is numeric and you had the following rows: { 3, 7, 40 }, the sort result would be { 3, 40, 7 }.</li>
<li>Header Freeze was problematic.  Implementing the {scrollable=true} feature as recommended by the documentation causes the table headers to be misaligned with the data in a fixed width table.</li>
<li>Paging uses the old school numbers method.  This wasn&#8217;t a deal breaker, since I classified this feature as a luxury item.</li>
</ul>
<p>Granted, the DataTable in it&#8217;s current form is a beta component, but that 0.5 MB ExtJS hit is looking pretty nice right now.</p>
<p><strong>Minor Update</strong>: to do a fixed width table that will overflow horizontally, this is the method you can use:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #cc00cc;">#dataTableId</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #808080; font-style: italic;">/* change this to whatever id you're using to hold the dataTable */</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">520px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* put in your own fixed width */</span>
	overflow-x<span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	overflow-y<span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.yui-dt-headtext</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.yui-dt-headcontainer</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">static</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* without this declaration, the headers weren't horizontally scrolling with the data in IE6 */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/problems-with-yui-datatable/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>YUI Button Lite</title>
		<link>http://www.zachleat.com/web/yui-button-lite/</link>
		<comments>http://www.zachleat.com/web/yui-button-lite/#comments</comments>
		<pubDate>Sat, 24 Mar 2007 05:13:47 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Button]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/03/23/yui-button-lite/</guid>
		<description><![CDATA[Do you want the cool clean look of the new YUI Button component, but without all the seedy overhead of split buttons or button groups or components that shouldn&#8217;t even be pigeonholed into a button component to begin with? Keep in mind that this approach only works for the method called &#8220;Using pre-defined Button Control [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want the cool clean look of the new YUI Button component, but without all the seedy overhead of split buttons or button groups or components that shouldn&#8217;t even be pigeonholed into a button component to begin with?  Keep in mind that this approach only works for the method called &#8220;<a href="http://developer.yahoo.com/yui/button/#buildingfromtemplate">Using pre-defined Button Control HTML.</a>&#8221;</p>
<p>Well, here&#8217;s the trick to do it.</p>
<p>Create the button as the YUI Button Examples and Documentation say to do so.  Include the Button CSS file button/assets/button.css.  But just <strong>don&#8217;t</strong> include the YUI JavaScript file button-beta[-min].js.</p>
<p>Instead, use the following JavaScript to replace the functions for button coloring for hover, focus, and active.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> window<span style="color: #339933;">,</span> <span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> yuiButtons <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'yuibutton'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'span'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> yuiButtons<span style="color: #339933;">,</span> <span style="color: #3366CC;">'mouseover'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'hover'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> yuiButtons<span style="color: #339933;">,</span> <span style="color: #3366CC;">'mouseout'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'hover'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> yuiButtons<span style="color: #339933;">,</span> <span style="color: #3366CC;">'mousedown'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'active'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> yuiButtons<span style="color: #339933;">,</span> <span style="color: #3366CC;">'mouseup'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'active'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> yuiButtons<span style="color: #339933;">,</span> <span style="color: #3366CC;">'focus'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'focus'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> yuiButtons<span style="color: #339933;">,</span> <span style="color: #3366CC;">'blur'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Dom</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'focus'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you&#8217;re just using the standard buttons anyway, you&#8217;re going to see a speed improvement in performance on hover color changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/yui-button-lite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fundamental Problem with YUI Button</title>
		<link>http://www.zachleat.com/web/fundamental-problem-with-yui-button/</link>
		<comments>http://www.zachleat.com/web/fundamental-problem-with-yui-button/#comments</comments>
		<pubDate>Thu, 22 Mar 2007 22:23:23 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Button]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/03/22/fundamental-problem-with-yui-button/</guid>
		<description><![CDATA[Buttons! Let&#8217;s make them obvious and good looking. Let&#8217;s make them have inline images and cool hover colors. Let&#8217;s make them three dimensional. Especially so, let&#8217;s make them from markup so that we don&#8217;t take functionality away from technology disabled users. Ruh roh Shaggy! The YUI Button component is misbehaving. It is taking away the [...]]]></description>
			<content:encoded><![CDATA[<p>Buttons!  Let&#8217;s make them obvious and good looking.  Let&#8217;s make them have inline images and cool hover colors.  Let&#8217;s make them three dimensional.  Especially so, let&#8217;s make them from markup so that we don&#8217;t take functionality away from technology disabled users.</p>
<p>Ruh roh Shaggy!  The <a href="http://yuiblog.com/blog/2007/02/20/yui-220-released/">YUI Button</a> component is misbehaving.  It is taking away the submit event fired when the button is clicked and firing the submit() function programmatically.</p>
<p>So, how do you fire the listener functions that are waiting for the submit event to fire, while at the same time using the sleek buttons provided by YUI?</p>
<p>Try this plug and play function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #660066;">widget</span>.<span style="color: #660066;">Button</span>.<span style="color: #660066;">prototype</span>._submitForm <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> oForm <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getForm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>oForm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        YAHOO.<span style="color: #660066;">widget</span>.<span style="color: #660066;">Button</span>.<span style="color: #660066;">addHiddenFieldsToForm</span><span style="color: #009900;">&#40;</span>oForm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">createHiddenField</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> listeners <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">getListeners</span><span style="color: #009900;">&#40;</span> oForm<span style="color: #339933;">,</span> <span style="color: #3366CC;">'submit'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> submitForm <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> listeners.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> listeners<span style="color: #009900;">&#91;</span> j <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">fn</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span> listeners<span style="color: #009900;">&#91;</span> j <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">adjust</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> submitForm <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> submitForm <span style="color: #009900;">&#41;</span> oForm.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(Make sure you include this after you&#8217;ve loaded the YUI Button javascript file.) There are a few caveats to this approach.</p>
<p>First, you&#8217;ll have to remove any references to the event object inside your listener function (most of the examples use the variable e). For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span> myForm<span style="color: #339933;">,</span> <span style="color: #3366CC;">'submit'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Inside my submit listener functions, I just check to make sure e is not null prior to using it.</p>
<p>Second, if you wish to cancel the submit, you&#8217;ll have to return false inside of your submit listener function.</p>
<p>A sleeker approach would be to revert back to having the button fire the &#8216;submit&#8217; event.  But I&#8217;ll leave that as an exercise to the original developer, Mr. Todd Kloots (props).</p>
<p>Update: After a little more code searching, it would seem like the submit event is never being canceled by the YUI Button javascript.  However, when you comment out the line that that fires the submit programmatically (oForm.submit();), the form still isn&#8217;t submitted.  I&#8217;ll have to research a bit more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/fundamental-problem-with-yui-button/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

