<?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>Haastek &#187; JavaScript</title>
	<atom:link href="http://haastek.co.uk/category/js/feed/" rel="self" type="application/rss+xml" />
	<link>http://haastek.co.uk</link>
	<description>the blog of Luke Haas, focused on design and web-development</description>
	<lastBuildDate>Mon, 22 Feb 2010 19:28:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introduction to jQuery</title>
		<link>http://haastek.co.uk/2009/12/introduction-to-jquery/</link>
		<comments>http://haastek.co.uk/2009/12/introduction-to-jquery/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 19:00:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://haastek.co.uk/?p=19</guid>
		<description><![CDATA[
jQuery is a javascript framework, first released by John Resig in 2006. Today it is the most popular JavaScript framework in the world. jQuery appeals to a wide variety of JavaScript developers, from those just starting out, to seasoned experts. This is in no small part due to the elegance and simplicity of jQuery, with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://haastek.co.uk/2009/12/introduction-to-jquery/"><img class="alignnone size-full wp-image-20" title="jquery" src="http://haastek.co.uk/wp-content/uploads/2009/12/jquery.jpg" alt="jquery" width="565" height="96" /></a><br />
jQuery is a javascript framework, first released by John Resig in 2006. Today it is the most popular JavaScript framework in the world. jQuery appeals to a wide variety of JavaScript developers, from those just starting out, to seasoned experts. This is in no small part due to the elegance and simplicity of jQuery, with just a few lines of clear and concise code you can create anything from complex animations to advanced ajax functionality.</p>
<p>In this tutorial I will start from the beginning and give you a brief introduction to some of jQuery&#8217;s core concepts such as element selection, manipulation and events.
<p><span id="more-19"></span></p>
<p>The first thing you&#8217;ll need to do is download the jQuery core library from <a href="http://jquery.com/">jquery.com</a> and add a reference to it in your html page.</p>
<p>Now we can start writing some code. As the majority of stuff you&#8217;re most likely to do with jQuery will involve the DOM in some way, we&#8217;ll need to start with the jQuery ready event. This is an event that gets triggered when the page has loaded and the DOM is ready to be accessed.</p>
<pre class="brush: js">
$(document).ready(function() {

});
</pre>
<p>From within this function we can select and manipulate DOM elements. If, for example, you wanted to select an element by it&#8217;s ID, or select a group of elements by their class name, you can do this by using CSS selectors. This is done like this:</p>
<pre class="brush: js">
$(&quot;#nav&quot;)
//this would select an element with the ID of nav
$(&quot;.title&quot;)
//this would select all elements with the class name title
$(&quot;p&quot;)
//this would select all paragraphs
</pre>
<p>Once you have selected an element, or a group of elements, you have a vast array of options when it comes to dealing with that selection. You could:</p>
<pre class="brush: js">
$(&quot;#nav&quot;).css({&#039;width&#039;:&#039;500px&#039;,&#039;height&#039;:&#039;200px&#039;});
//alter it&#039;s css properties
var cont = $(&quot;#nav&quot;).html();
//assign its contents to a variable
$(&quot;#nav&quot;).html(&quot;insert this text&quot;);
//assign content to it
$(&quot;#nav&quot;).hide();
//perform an animation on it
</pre>
<p>And much more, you can also apply events to the elements you have selected. Here are some examples:</p>
<pre class="brush: js">
$(&quot;.title&quot;).click(function() {
//this triggers on a mouse click
});

$(&quot;input&quot;).focus(function() {
//this triggers when an input field gets focus
});

$(&quot;input&quot;).blur(function() {
//this triggers when an input field loses focus
});

$(&quot;#nav&quot;).mouseenter(function() {
//this triggers when the mouse moves over the element
});

$(&quot;#nav&quot;).mouseleave(function() {
//this triggers when the mouse moves over the element
});
</pre>
<p>Now we can put this all togther and create a basic function that gets triggered when an element with the ID of &#8216;nav&#8217; gets clicked on, which then causes the text colour of all the paragraphs on the page to be set to red and their content to be set to the text &#8216;This is a paragraph&#8217;:</p>
<pre class="brush: js">
$(document).ready(function() {
	$(&quot;#nav&quot;).click(function() {
	$(&quot;p&quot;).css({&#039;color&#039;:&#039;#ff0000&#039;});
	$(&quot;p&quot;).html(&quot;This is a paragraph&quot;);
});
});
</pre>
<p>This has been a basic introduction to jQuery, showing you some of the core concepts and functionality. The amount you can do with jQuery is vast and to get a better idea of this, I suggest you have a read through the documentation on the <a href="http://jquery.com/">jQuery</a> site.  It&#8217;s very thorough and informative with lots of great examples and demonstrations. Other useful jQuery sites include <a href="http://jqueryfordesigners.com/">jQuery for Designers</a> and <a href="http://jquery-howto.blogspot.com/">jQuery Howto</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://haastek.co.uk/2009/12/introduction-to-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
