<?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>tgreenaway.com &#187; example</title>
	<atom:link href="http://tgreenaway.com/tag/example/feed/" rel="self" type="application/rss+xml" />
	<link>http://tgreenaway.com</link>
	<description>Creatively engineered.</description>
	<lastBuildDate>Sat, 30 May 2009 06:06:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Debugging Javascript</title>
		<link>http://tgreenaway.com/2008/08/debugging-javascript/</link>
		<comments>http://tgreenaway.com/2008/08/debugging-javascript/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 15:39:08 +0000</pubDate>
		<dc:creator>TCMG</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tgreenaway.com/?p=49</guid>
		<description><![CDATA[So far my experience with Javascript has not required too much dealing with its raw form. I&#8217;m a big fan of the jQuery library and I&#8217;ve heard described as a swiss army knife for Javascript. I think that&#8217;s an understatement though, it goes beyond just being a toolset. I believe it is a framework in [...]]]></description>
			<content:encoded><![CDATA[<p>So far my experience with Javascript has not required too much dealing with its raw form. I&#8217;m a big fan of the jQuery library and I&#8217;ve heard described as a swiss army knife for Javascript. I think that&#8217;s an understatement though, it goes beyond just being a toolset. I believe it is a framework in its own right. And in fact, it pushes all your Javascript code into a more structured form.</p>
<p>I recently fixed a problem with a website that was developed by someone using raw Javascript. Basically it failed to work in IE. The underlying problem was that IE doesn&#8217;t recognise the visual text of a drop down select box in the DOM of the page as the &#8216;value&#8217; of the element in the drop down select box.</p>
<p>So if you selected &#8220;5pm&#8221; from the box, the Javascript can&#8217;t be:</p>
<pre>
<pre class="brush: jscript;">foo = frm.select[bar].value;</pre>
</pre>
<p>It has to be:</p>
<pre>
<pre class="brush: jscript;">foo = frm.select[bar].text;</pre>
</pre>
<p>If you want it to work across all the browsers. In jQuery, you would never even write code like the above. You&#8217;d be using the CSS selectors:</p>
<pre>
<pre class="brush: jscript;">$(&quot;#date_select&quot;).text();</pre>
</pre>
<p>The above would find the element with id &#8216;date_select&#8217; and extract its text. Why the dollar sign? It tells Javascript we&#8217;re dealing with the jQuery library.</p>
<p>So you see, jQuery just <em>looks </em>different to raw Javascript most of the time. For example, take a load of this raw Javascript:</p>
<pre>
<pre class="brush: jscript;">
document.getElementById(&amp;quot;x20&amp;quot;).style.display='none';
document.getElementById(&amp;quot;x21&amp;quot;).style.display='none';
document.getElementById(&amp;quot;x22&amp;quot;).style.display='none';

var d = frm.Dates;
var dval = d.options[d.selectedIndex].text;
var idx;

for (x=frm.Times.length;x&amp;gt;0;x=x-1)
{
        frm.Times.remove(x);
}
</pre>
</pre>
<p>Ugh, messy. jQuery steps away from the &#8216;document&#8217; rubbish by using the CSS selectors mentioned previously. And the for loop? jQuery provides you with functions to iterate throughout CSS selected elements:</p>
<pre>
<pre class="brush: jscript;">
$(&quot;#times_list li&quot;).each(function () {
  this.remove()
}
</pre>
</pre>
<p>Where &#8216;this&#8217; is one of the CSS selector&#8217;s matched elements, iterated by the &#8216;each&#8217; function.</p>
]]></content:encoded>
			<wfw:commentRss>http://tgreenaway.com/2008/08/debugging-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
