<?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>Ben Lobaugh Online &#187; jQuery</title>
	<atom:link href="http://ben.lobaugh.net/blog/category/computing/programming/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://ben.lobaugh.net/blog</link>
	<description>/(bb&#124;[^b]{2})/</description>
	<lastBuildDate>Mon, 21 May 2012 03:14:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Retrieve remote JSON content with jQuery</title>
		<link>http://ben.lobaugh.net/blog/586/retrieve-remote-json-content-with-jquery</link>
		<comments>http://ben.lobaugh.net/blog/586/retrieve-remote-json-content-with-jquery#comments</comments>
		<pubDate>Wed, 30 Jun 2010 20:03:58 +0000</pubDate>
		<dc:creator>blobaugh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://ben.lobaugh.net/blog/?p=586</guid>
		<description><![CDATA[I am currently working on an iPhone app using the PhoneGap project as a base. PhoneGap allows me to use my current web development knowledge to develop an application using HTML, CSS, and Javascript. A key component in almost all iPhone applications is retrieval of remote content. I am going to walk you through the [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on an iPhone app using the <a title="PhoneGap" href="http://www.phonegap.com/" onclick="return TrackClick('http%3A%2F%2Fwww.phonegap.com%2F','PhoneGap')" target="_blank">PhoneGap</a> project as a base. PhoneGap allows me to use my current web development knowledge to develop an application using HTML, CSS, and Javascript. A key component in almost all iPhone applications is retrieval of remote content. I am going to walk you through the steps I took while developing the iPhone app for <a title="Northwest Nazarene University" href="http://www.nnu.edu" onclick="return TrackClick('http%3A%2F%2Fwww.nnu.edu','Northwest+Nazarene+University')" target="_blank">Northwest Nazarene University</a>.</p>
<p>For ease of development purposes I have downloaded the <a title="jQuery" href="http://jquery.com/" onclick="return TrackClick('http%3A%2F%2Fjquery.com%2F','jQuery')" target="_blank">jQuery</a> library, version 1.4.2, to my local machine.</p>
<p>Let's start by creating a basic HTML file that we will manipulate as we go.</p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
                // We will fill in our code here
&nbsp;
// ]]&gt;&lt;/script&gt;</pre>
<p>We could statically build our own JSON string here, but since we are building an app to retreive remote content why don't we use an external source. There is a weather module in the NNU iPhone app that will do nicely. You can find it here http://www.nnu.edu/iphone/api/weather.php (No longer online <img src='http://ben.lobaugh.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  ) and the output should look something like</p>
<pre class="javascript"><span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">&quot;temp&quot;</span>:<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;70&quot;</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #3366CC;">&quot;condition&quot;</span>:<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;Fair&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#125;</span></pre>
<p>(At the time of writing this was correct, but the site is still in development and may change slightly)</p>
<p>Great, we have our source, now we need to pull the content from it. Luckily jQuery provides some handy tools for grabbing remote content, and specifically for JSON data. Here is where the first trick comes in, cross site scripting (XSS). XSS happens when a Javascript service attempts to pull content from another server. XSS has been used for malicious purposes in the past and is therefore tightly controlled. jQuery is supposed to be able to legitimately access remote content, but if you are having problems see my post <a href="http://ben.lobaugh.net/blog/578/phpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch" onclick="return TrackClick('http%3A%2F%2Fben.lobaugh.net%2Fblog%2F578%2Fphpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch','Enabling+XSS+for+iPhone+apps+with+PhoneGap+and+jQTouch')" onclick="return TrackClick('http%3A%2F%2Fben.lobaugh.net%2Fblog%2F578%2Fphpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch','Enabling+XSS+for+iPhone+apps+with+PhoneGap+and+jQTouch')">Enabling XSS for iPhone apps with PhoneGap and jQTouch</a> to learn how to configure your Apache server to allow the remote pull.</p>
<p>Let's see what the jQuery code looks like</p>
<pre class="javascript">$.<span style="color: #006600;">getJSON</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'http://www.nnu.edu/iphone/api/weather.php'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'
&nbsp;
'</span> + data.<span style="color: #006600;">temp</span> + <span style="color: #3366CC;">'
&nbsp;
'</span>
    + <span style="color: #3366CC;">'
&nbsp;
'</span> + data.<span style="color: #006600;">condition</span> + <span style="color: #3366CC;">'
&nbsp;
'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Using $.getJSON we can provide a callback for the returned JSON. I am going to use a dynamic function in this example, however you can also point it to a function name you define elsewhere. See <a href="http://api.jquery.com/jQuery.getJSON/" onclick="return TrackClick('http%3A%2F%2Fapi.jquery.com%2FjQuery.getJSON%2F','http%3A%2F%2Fapi.jquery.com%2FjQuery.getJSON%2F')" target="_blank">http://api.jquery.com/jQuery.getJSON/</a> for more information regarding the $.getJSON function.</p>
<p>After previewing the index.html file in your browser you should see</p>
<pre>73
&nbsp;
Fai</pre>
<p>Congratulations, you have successfully pulled remote JSON into your app!</p>
<p>You can download the complete source code <a href="http://ben.lobaugh.net/blog/wp-content/uploads/2010/06/json_demo_weather.zip" onclick="return TrackClick('http%3A%2F%2Fben.lobaugh.net%2Fblog%2Fwp-content%2Fuploads%2F2010%2F06%2Fjson_demo_weather.zip','here')">here</a></p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
                // We will fill in our code here
           $(document).ready(function() {
               $('body').html('
&nbsp;
' + data.temp + '
&nbsp;
'
                                + '
&nbsp;
' + data.condition + '
&nbsp;
');
               });
            }); 
&nbsp;
// ]]&gt;&lt;/script&gt;</pre>
<p><strong>Complex Objects</strong><br />
Let's take it a step further now and work with some complex objects. We will be using the NNU iPhone app's JSON news feed located here http://www.nnu.edu/iphone/api/rssproxy.php?url=nnu_news (No longer online <img src='http://ben.lobaugh.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  ). I am not going to post the JSON string because it gets quite long. You can view it by loading that URI into your browser.</p>
<p>Again, create your initial basic HTML index file. We will reuse the one listed in the above section.</p>
<p>Now the code for this section is going to be a little more intense. The object we are getting back contains multiple array of information. We will need to loop over the array in order to grab the individual news elements and display their contents. jQuery provides us with the $.each function (See <a href="http://api.jquery.com/each/" onclick="return TrackClick('http%3A%2F%2Fapi.jquery.com%2Feach%2F','http%3A%2F%2Fapi.jquery.com%2Feach%2F')" target="_blank">http://api.jquery.com/each/</a>) which we can hand the JSON data off to and get to the good stuff. Let's see what this code will look like</p>
<pre class="javascript">$.<span style="color: #006600;">getJSON</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'http://www.nnu.edu/iphone/api/rssproxy.php?url=nnu_news'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        $.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span>data, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #000066; font-weight: bold;">item</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'&lt;strong&gt;'</span> + <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #006600;">title</span> + <span style="color: #3366CC;">'&lt;/strong&gt;'</span><span style="color: #66cc66;">&#41;</span>;
                $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'
&lt;span style=&quot;font-size: 85%;&quot;&gt;Published:'</span> + <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #006600;">pubDate</span> + <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #66cc66;">&#41;</span>;
                $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'
&nbsp;
'</span> + <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #006600;">description</span> + <span style="color: #3366CC;">'
&nbsp;
'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>If everything was written correctly you should now see a listing of the news items when you refresh the index.html file in your browser.</p>
<p>You can download the full source <a href="http://ben.lobaugh.net/blog/wp-content/uploads/2010/06/json_demo_news.zip" onclick="return TrackClick('http%3A%2F%2Fben.lobaugh.net%2Fblog%2Fwp-content%2Fuploads%2F2010%2F06%2Fjson_demo_news.zip','here')">here</a></p>
<p>Having Trouble?<br />
If you are receiving a denied error from the server, or a 200 success message with no content you may be experiencing cross site scripting (XSS) issues. Take a gander at my post<a href="http://ben.lobaugh.net/blog/578/phpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch" onclick="return TrackClick('http%3A%2F%2Fben.lobaugh.net%2Fblog%2F578%2Fphpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch','Enabling+XSS+for+iPhone+apps+with+PhoneGap+and+jQTouch')" onclick="return TrackClick('http%3A%2F%2Fben.lobaugh.net%2Fblog%2F578%2Fphpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch','Enabling+XSS+for+iPhone+apps+with+PhoneGap+and+jQTouch')"> Enabling XSS for iPhone apps with PhoneGap and jQTouch</a> to prevent this behavior in the future</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.lobaugh.net/blog/586/retrieve-remote-json-content-with-jquery/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>PHP+Apache: Enabling XSS for iPhone apps with PhoneGap and jQTouch</title>
		<link>http://ben.lobaugh.net/blog/578/phpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch</link>
		<comments>http://ben.lobaugh.net/blog/578/phpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch#comments</comments>
		<pubDate>Thu, 24 Jun 2010 17:40:22 +0000</pubDate>
		<dc:creator>blobaugh</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://ben.lobaugh.net/blog/?p=578</guid>
		<description><![CDATA[I am currently working on developing an iPhone app for Northwest Nazarene University. Part of this app will need to connect to the school's webserver to retreive items such as news feeds and shared photo galleries. Being primarily a web developer I have turned to two projects created by Nitobi persons, PhoneGap and jQTouch. PhoneGap [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on developing an iPhone app for<a title="Northwest Nazarene University" href="http://www.nnu.edu" onclick="return TrackClick('http%3A%2F%2Fwww.nnu.edu','Northwest+Nazarene+University')" target="_blank"> Northwest Nazarene University</a>. Part of this app will need to connect to the school's webserver to retreive items such as news feeds and shared photo galleries. Being primarily a web developer I have turned to two projects created by <a title="Nitobi" href="http://www.nitobi.com/" onclick="return TrackClick('http%3A%2F%2Fwww.nitobi.com%2F','Nitobi')" target="_blank">Nitobi</a> persons, <a title="PhoneGap" href="http://www.phonegap.com/" onclick="return TrackClick('http%3A%2F%2Fwww.phonegap.com%2F','PhoneGap')" onclick="return TrackClick('http%3A%2F%2Fwww.phonegap.com%2F','PhoneGap')" target="_blank">PhoneGap</a> and <a title="jQTouch" href="http://www.jqtouch.com/" onclick="return TrackClick('http%3A%2F%2Fwww.jqtouch.com%2F','jQTouch')" onclick="return TrackClick('http%3A%2F%2Fwww.jqtouch.com%2F','jQTouch')" target="_blank">jQTouch</a>.</p>
<p><a title="PhoneGap" href="http://www.phonegap.com/" onclick="return TrackClick('http%3A%2F%2Fwww.phonegap.com%2F','PhoneGap')" onclick="return TrackClick('http%3A%2F%2Fwww.phonegap.com%2F','PhoneGap')" target="_blank">PhoneGap</a> allows me to use my current HTML, CSS, and Javascript knowledge to build a site. Then using the PhoneGap xcode project I simply drop the web files into a directory and PhoneGap transforms them into a glorious iPhone app.</p>
<p><a title="jQTouch" href="http://www.jqtouch.com/" onclick="return TrackClick('http%3A%2F%2Fwww.jqtouch.com%2F','jQTouch')" onclick="return TrackClick('http%3A%2F%2Fwww.jqtouch.com%2F','jQTouch')" target="_blank">jQTouch</a> is a jQuery based library that makes the app look and feel like a real iPhone app.</p>
<p>This setup worked beautifully until I needed to connect to the school's webserver and retreive content. I began to run into cross site scripting (XSS) headaches. After days of pounding my head into my desk I ran across a neat little feature in <a title="Apache HTTP Server" href="http://httpd.apache.org/" onclick="return TrackClick('http%3A%2F%2Fhttpd.apache.org%2F','Apache+HTTP+Server')" target="_blank">Apache</a> that allows you to turn off the XSS protection on the server. You may be thinking that sounds insecure, and you would be right, but if you are trying to pull content off your server with Javascript from remote locations it may be just the thing you need to get it working. This does not come built in Apache, it is a module you have to add in. It was pretty trivial. Here are the <a title="mod_headers in Ubuntu" href="http://harthur.wordpress.com/2009/10/15/configure-apache-to-accept-cross-site-xmlhttprequests-on-ubuntu/" onclick="return TrackClick('http%3A%2F%2Fharthur.wordpress.com%2F2009%2F10%2F15%2Fconfigure-apache-to-accept-cross-site-xmlhttprequests-on-ubuntu%2F','Permanent+Link+to+%26quot%3BConfigure+Apache+To++Accept+Cross-Site+XMLHttpRequests+on%C2%A0Ubuntu%26quot%3B')" onclick="return TrackClick('http%3A%2F%2Fharthur.wordpress.com%2F2009%2F10%2F15%2Fconfigure-apache-to-accept-cross-site-xmlhttprequests-on-ubuntu%2F','mod_headers+in+Ubuntu')" target="_blank">directions for setting up mod_headers in Ubuntu</a></p>
<p>To check and see if mod_headers was actually loaded save the following to a <a title="PHP" href="http://php.net" onclick="return TrackClick('http%3A%2F%2Fphp.net','PHP')" target="_blank">PHP</a> file and view it from the server in your browser</p>
<pre class="php"><a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span>apache_get_modules<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>If that was successful mod_headers should be listed. You can now move on to the more fun stuff.</p>
<p>There are two ways in which you can allow XSS. The first is through a .htaccess file. This method works great, however it enables XSS for all files in the directory. The second is through PHP header(). The PHP method allows you to target more specifically what files are XSS capable, and even would allow you to do some other safety checks in your code before setting the XSS header.</p>
<p>.htaccess</p>
<pre class="bash">Header add Access-Control-Allow-Origin <span style="color: #ff0000;">&quot;*&quot;</span>
&nbsp;</pre>
<p>PHP</p>
<pre class="php"><a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Access-Control-Allow-Origin: *'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Another thing to take note of is the *. The * means anyone from anywhere may do XSS. You can however specify specific hosts that have access. See the link at the bottom of this post for more information on that.</p>
<p>Congratulations! You should now have an XSS compatible website. Make extra sure that all of your security is in place because XSS opens up a whole new can of worms for crackers. Ensure all input from users is cleaned before it touches your database or anything else remotely sensitive.</p>
<p>Articles that helped me along the way:<br />
<a href="http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains" onclick="return TrackClick('http%3A%2F%2Fstackoverflow.com%2Fquestions%2F1653308%2Faccess-control-allow-origin-multiple-origin-domains','Access-Control-Allow-Origin+Multiple+Origin++Domains%3F')" target="_blank">Access-Control-Allow-Origin Multiple Origin  Domains?</a><br />
<a title="Permanent Link to &quot;Configure Apache To  Accept Cross-Site XMLHttpRequests on Ubuntu&quot;" rel="bookmark" href="http://harthur.wordpress.com/2009/10/15/configure-apache-to-accept-cross-site-xmlhttprequests-on-ubuntu/" onclick="return TrackClick('http%3A%2F%2Fharthur.wordpress.com%2F2009%2F10%2F15%2Fconfigure-apache-to-accept-cross-site-xmlhttprequests-on-ubuntu%2F','Permanent+Link+to+%26quot%3BConfigure+Apache+To++Accept+Cross-Site+XMLHttpRequests+on%C2%A0Ubuntu%26quot%3B')" onclick="return TrackClick('http%3A%2F%2Fharthur.wordpress.com%2F2009%2F10%2F15%2Fconfigure-apache-to-accept-cross-site-xmlhttprequests-on-ubuntu%2F','mod_headers+in+Ubuntu')" target="_blank">Configure Apache To  Accept Cross-Site XMLHttpRequests on Ubuntu</a><br />
<a title="HTTP Access Control - Mozilla" href="https://developer.mozilla.org/en/http_access_control" onclick="return TrackClick('https%3A%2F%2Fdeveloper.mozilla.org%2Fen%2Fhttp_access_control','HTTP+Access+Control+-+Mozilla')" target="_blank">HTTP Access Control</a><br />
<a title="Server Side Access Control - Mozilla" href="https://developer.mozilla.org/En/Server-Side_Access_Control" onclick="return TrackClick('https%3A%2F%2Fdeveloper.mozilla.org%2FEn%2FServer-Side_Access_Control','Server+Side+Access+Control+-+Mozilla')" target="_blank">Server-Side Access Control</a><br />
<a href="http://www.hunlock.com/blogs/Social_Javascript_%28cross-site_ajax%29" onclick="return TrackClick('http%3A%2F%2Fwww.hunlock.com%2Fblogs%2FSocial_Javascript_%2528cross-site_ajax%2529','Social+Javascript+%28cross-site+ajax%29')" target="_blank">Social Javascript (cross-site ajax)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ben.lobaugh.net/blog/578/phpapache-enabling-xss-for-iphone-apps-with-phonegap-and-jqtouch/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>jQuery: Selecting only the first level children</title>
		<link>http://ben.lobaugh.net/blog/573/jquery-selecting-only-the-first-level-children</link>
		<comments>http://ben.lobaugh.net/blog/573/jquery-selecting-only-the-first-level-children#comments</comments>
		<pubDate>Tue, 22 Jun 2010 18:50:02 +0000</pubDate>
		<dc:creator>blobaugh</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://ben.lobaugh.net/blog/?p=573</guid>
		<description><![CDATA[Using the .not() operator with jQuery it is possible to select only the first level of children of an element. This could come in handy on a menu for instance. Let's see what the menu code looks like. &#160; &#60;ul&#62; &#60;li&#62;Item &#60;ul&#62; &#60;li&#62;Sub&#60;/li&#62; &#60;li&#62;Sub2&#60;/li&#62; &#60;li&#62;Sub3&#60;/li&#62; &#60;/ul&#62; &#60;/li&#62; &#60;li&#62;Item2&#60;/li&#62; &#60;li&#62;Item3&#60;/li&#62; &#60;/ul&#62; &#160; We are trying to [...]]]></description>
			<content:encoded><![CDATA[<p>Using the .not() operator with jQuery it is possible to select only the first level of children of an element. This could come in handy on a menu for instance. Let's see what the menu code looks like.</p>
<pre>&nbsp;
&lt;ul&gt;
&lt;li&gt;Item
&lt;ul&gt;
&lt;li&gt;Sub&lt;/li&gt;
&lt;li&gt;Sub2&lt;/li&gt;
&lt;li&gt;Sub3&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Item2&lt;/li&gt;
&lt;li&gt;Item3&lt;/li&gt;
&lt;/ul&gt;
&nbsp;</pre>
<p>We are trying to get ul li, but not ul li ul li. jQuery has a brilliant method to select page elements like so:</p>
<pre class="javascript">&nbsp;
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'ul li'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>However this will get ALL of the li elements not matter the depth. We only want the first level of li. Luckily jQuery again has a method to accomplish this using .not()</p>
<pre class="javascript">&nbsp;
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'ul li'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">not</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'ul li ul li'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>Voila! We now have only the first level of li elements</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.lobaugh.net/blog/573/jquery-selecting-only-the-first-level-children/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery: Detect enter key</title>
		<link>http://ben.lobaugh.net/blog/556/jquery-detect-enter-key</link>
		<comments>http://ben.lobaugh.net/blog/556/jquery-detect-enter-key#comments</comments>
		<pubDate>Mon, 07 Jun 2010 03:54:39 +0000</pubDate>
		<dc:creator>blobaugh</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://ben.lobaugh.net/blog/?p=556</guid>
		<description><![CDATA[Sometimes it is nice to be able to detect when the user has pressed the enter. This is great for super custom forms and Javascript games. Or maybe a totally custom built app that is waiting for the user to hit enter for some reason. But how to detect the enter key? Luckily jQuery once [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is nice to be able to detect when the user has pressed the enter. This is great for super custom forms and Javascript games. Or maybe a totally custom built app that is waiting for the user to hit enter for some reason. But how to detect the enter key? Luckily <a title="jQuery" href="http://jquery.com" onclick="return TrackClick('http%3A%2F%2Fjquery.com','jQuery')" target="_blank">jQuery</a> once again comes in handy. Check out the following bit of code to grab the enter key.</p>
<pre class="javascript">&nbsp;
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#keyed_element'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">keyup</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>e.<span style="color: #006600;">keyCode</span> == <span style="color: #CC0000;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #009900; font-style: italic;">// Put your key handler code here</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://ben.lobaugh.net/blog/556/jquery-detect-enter-key/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Oh How I Love Thee</title>
		<link>http://ben.lobaugh.net/blog/386/jquery-oh-how-i-love-thee</link>
		<comments>http://ben.lobaugh.net/blog/386/jquery-oh-how-i-love-thee#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:03:37 +0000</pubDate>
		<dc:creator>blobaugh</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://ben.lobaugh.net/blog/?p=386</guid>
		<description><![CDATA[I started using jQuery last week and I am finding it to be a great library so far. It is very easy to interact with elements on the page in fun and creative ways. As a sample, I have been working with the Northwest Nazarene University web team and they wanted to develop a simple [...]]]></description>
			<content:encoded><![CDATA[<p>I started using <a title="jQuery" href="http://jquery.com" onclick="return TrackClick('http%3A%2F%2Fjquery.com','jQuery')" onclick="return TrackClick('http%3A%2F%2Fjquery.com','jQuery')" target="_blank">jQuery</a> last week and I am finding it to be a great library so far. It is very easy to interact with elements on the page in fun and creative ways.</p>
<p>As a sample, I have been working with the <a title="Northwest Nazarene University" href="http://www.nnu.edu" onclick="return TrackClick('http%3A%2F%2Fwww.nnu.edu','Northwest+Nazarene+University')" onclick="return TrackClick('http%3A%2F%2Fwww.nnu.edu','Northwest+Nazarene+University')" target="_blank">Northwest Nazarene University</a> web team and they wanted to develop a simple wizard they can put on any page that will help prospective students find the degree they are interested in. I decided to tackle that task. At first I was looking at slide show sample, then one of the other developers showed me the beauty of .load(), which allows me to load into any arbitrary element the contents of any file or web address. After playing with .load() and the event handlers for an hour I figured out a way to implement what they wanted. It took me maybe 4 hours going from ground zero of no knowledge on the subject to implementing a working system complete with calls to a backend <a title="PHP Project Site" href="http://php.net" onclick="return TrackClick('http%3A%2F%2Fphp.net','PHP+Project+Site')" target="_blank">PHP</a> file that gets the contents for the wizard from the database. <a title="jQuery" href="http://jquery.com" onclick="return TrackClick('http%3A%2F%2Fjquery.com','jQuery')" onclick="return TrackClick('http%3A%2F%2Fjquery.com','jQuery')" target="_blank">jQuery</a> is really neat, I highly encourage other web developers to check it out. A working sample may be found here or on <a title="Northwest Nazarene University" href="http://www.nnu.edu" onclick="return TrackClick('http%3A%2F%2Fwww.nnu.edu','Northwest+Nazarene+University')" onclick="return TrackClick('http%3A%2F%2Fwww.nnu.edu','Northwest+Nazarene+University')" target="_blank">NNU's website</a>.</p>
<p>Here is the jQuery code I used. Try not to be too critical, I am positive there has to be a better way of doing this. I still am learning the vast amount of options available to me in jQuery.</p>
<pre class="php">&nbsp;
&lt;script type=<span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;
&nbsp;
$<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.ready<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	$<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'#programs'</span><span style="color: #66cc66;">&#41;</span>.load<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'programs.php'</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Load the degree options</span>
           $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'.choice'</span><span style="color: #66cc66;">&#41;</span>.bind<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'click'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Load the school in that degree</span>
	        $<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'.choice'</span><span style="color: #66cc66;">&#41;</span>.bind<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'click'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Load the list of degrees</span>
						$<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'#programs'</span><span style="color: #66cc66;">&#41;</span>.load<span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span>this<span style="color: #66cc66;">&#41;</span>.attr<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'href'</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
							$<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'.choice'</span><span style="color: #66cc66;">&#41;</span>.bind<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'click'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
								$<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'#programs'</span><span style="color: #66cc66;">&#41;</span>.load<span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span>this<span style="color: #66cc66;">&#41;</span>.attr<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'href'</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Load a degree</span>
					                        <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
							<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;			
		 <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
 <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://ben.lobaugh.net/blog/386/jquery-oh-how-i-love-thee/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

