<?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>Didsbury Design Blog &#187; javascript</title>
	<atom:link href="http://blog.didsburydesign.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.didsburydesign.com</link>
	<description>Web Design and Development</description>
	<lastBuildDate>Fri, 04 Nov 2011 16:37:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to: Use JQuery &#8211; The Basics</title>
		<link>http://blog.didsburydesign.com/2010/01/tutorial-how-to-jquery-basics/</link>
		<comments>http://blog.didsburydesign.com/2010/01/tutorial-how-to-jquery-basics/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 00:04:33 +0000</pubDate>
		<dc:creator>Didsbury Design</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.zero7web.com/?p=162</guid>
		<description><![CDATA[JQuery Basics
This post will show you some of the basics of JQuery. It is not an in depth tutorial but will give you some pointers to get you started with JQuery.
OK, the first piece of code you need to use JQuery is a link to the JQuery JS library. First, download the latest JQuery Library [...]]]></description>
			<content:encoded><![CDATA[<p><strong>JQuery Basics</strong><br />
This post will show you some of the basics of JQuery. It is not an in depth tutorial but will give you some pointers to get you started with JQuery.<br />
OK, the first piece of code you need to use JQuery is a link to the JQuery JS library. First, download the latest JQuery Library from the following link&#8230;.<br />
http://docs.jquery.com/Downloading_jQuery<br />
Then link to it like any other javascript file (like so)&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;./js/jquery-1.4.1.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Obviously choosing the correct path for your version web server file system setup.<br />
The next step after linking the JQuery library is to use it! Look at the following piece of code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;./js/jquery-1.4.1.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
		$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</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: #006600; font-style: italic;">// here is some code</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This is essentially the same as calling a standard Javascript Window.OnLoad event handler, except it&#8217;s the JQuery way.<br />
We are saying&#8230; when the document is ready (loaded) run some code.<br />
This is your basic first step to using JQuery. You can also use other event handlers to launch your code, or even call the functions directly, but often when using JQuery, especially for styling/design features, you will want to run the code and so this is the easiest way.<br />
At the moment this code is not very useful, as it doesn&#8217;t do anything, so let’s add a little more.<br />
Let’s create a very basic html page.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;JQuery Basics&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;a id=&quot;link1&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 1&lt;/a&gt;
		&lt;a id=&quot;link2&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 2&lt;/a&gt;
		&lt;a id=&quot;link3&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 3&lt;/a&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Ok now let’s add some JQuery&#8230;.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;JQuery Basics&lt;/title&gt;
		&lt;script src=&quot;./js/jquery-1.4.1.js&quot;&gt;&lt;/script&gt;
		&lt;script&gt;
			$(document).ready(function() {
				$('a').click(function() {
					alert(&quot;This is JQuery in action!&quot;);
				});
			});
		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;a id=&quot;link1&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 1&lt;/a&gt;
		&lt;a id=&quot;link2&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 2&lt;/a&gt;
		&lt;a id=&quot;link3&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 3&lt;/a&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Now save the file and open it in a web browser. When you click a link you should find you get a popup.<br />
Let’s examine this code a little further.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</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;">&quot;This is JQuery in action!&quot;</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>The first part</p>

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

<p> is a selector, the same as in CSS. Here we are saying apply to all of the A (anchor) tags in the document.<br />
Next we’re saying</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</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></pre></div></div>

<p>This means for all of those A tags use the click event handler.<br />
Finally we’re saying when that click event is found on an A tag</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><span style="color: #3366CC;">&quot;This is JQuery in action!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p> This generates the popup.<br />
In this example we chose to use</p>

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

<p> as our selector, but there are many other ways we can select elements.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#link1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</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></pre></div></div>

<p> This is the same as the getElementByID function that is commonly used in JavaScript. Here we are selecting the element with the ID “link1”.<br />
We could also use</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myLink'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</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></pre></div></div>

<p>to select all elements with the class name “myLink”.</p>
<p>In our examples we have used the click event handler to launch the code when the link is clicked. We don’t have to add an event handler here if we don’t want to.<br />
Let’s look at another example.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;JQuery Basics&lt;/title&gt;
		&lt;script src=&quot;./js/jquery-1.4.1.js&quot;&gt;&lt;/script&gt;
		&lt;script&gt;
			$(document).ready(function() {
				$('a').addClass(&quot;red&quot;);
			});
		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;a id=&quot;link1&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 1&lt;/a&gt;
		&lt;a id=&quot;link2&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 2&lt;/a&gt;
		&lt;a id=&quot;link3&quot; class=&quot;myLink&quot; href=&quot;#&quot;&gt;Link 3&lt;/a&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>This sets all A tags in documents to have the class “red”.<br />
This is a basic class which is built into the JQuery library, but you could just as easily add your own class.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;JQuery Basics&lt;/title&gt;
		&lt;script src=&quot;./js/jquery-1.4.1.js&quot;&gt;&lt;/script&gt;
		&lt;script&gt;
			$(document).ready(function() {
				$('a').addClass(&quot;myClass&quot;);
			});
		&lt;/script&gt;
		&lt;style&gt;
			.myClass {
				color:blue;
				text-decoration:underline;
			}
		&lt;/style&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;a id=&quot;link1&quot; href=&quot;#&quot;&gt;Link 1&lt;/a&gt;
		&lt;a id=&quot;link2&quot; href=&quot;#&quot;&gt;Link 2&lt;/a&gt;
		&lt;a id=&quot;link3&quot; href=&quot;#&quot;&gt;Link 3&lt;/a&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>You could also use first, last, parent and child selectors just like in CSS. For example</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;myClass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>to select the first of the link tags and apply the class “myClass” just to that first link.</p>
<p>These are just a few very basic examples of how you can start using JQuery, look out for more posts in the future where we will show you some of the many other exciting features of JQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.didsburydesign.com/2010/01/tutorial-how-to-jquery-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

