<?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>FaraJoomla Web Design and Development &#187; jQuery</title>
	<atom:link href="http://www.farajoomla.com/category/blog/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.farajoomla.com</link>
	<description>FaraJoomla Web Design and Development</description>
	<lastBuildDate>Sat, 29 Oct 2011 17:49:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Accordion with jQuery and CSS</title>
		<link>http://www.farajoomla.com/2010/05/accordion-with-jquery-and-css/</link>
		<comments>http://www.farajoomla.com/2010/05/accordion-with-jquery-and-css/#comments</comments>
		<pubDate>Mon, 24 May 2010 15:30:47 +0000</pubDate>
		<dc:creator>Faramarz</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.farajoomla.com/?p=359</guid>
		<description><![CDATA[The jQuery accordion plugin works with nested lists or just nested divs. There are also some options available to specify the structure, the active element (to display at first) and to customize animation. This plugin will come in handy when you are dealing with orgonizing a good chuck of content. HTML Markup In this markup [...]]]></description>
			<content:encoded><![CDATA[<p>The jQuery accordion plugin works with nested lists or just nested divs. There are also some options available to specify the structure, the active element (to display at first) and to customize animation. </p>
<p>This plugin will come in handy when you are dealing with orgonizing a good chuck of content. </p>
<h2>HTML Markup</h2>
<p>In this markup I&#8217;m using nested divs, an &lt;h3&gt; is the heading of accordion items and a nested &lt;div class=&quot;container_accordion&quot;&gt; to show the content of each item.</p>
<pre class="brush: html">
&lt;h3 class=&quot;click_accordion&quot;&gt;&lt;a href=&quot;#&quot;&gt;Web Design&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;container_accordion&quot;&gt;
  &lt;div class=&quot;content_accordion&quot;&gt;
    &lt;h2&gt;Custom Website Designs&lt;/h2&gt;
    &lt;p&gt;If your looking for a fresh eye-catching custom website design then we can develop a professional high quality website for you which is designed to your exact specifications.&lt;/p&gt;
    &lt;p&gt;Great websites do not need to cost an arm and a leg. Our process is that of getting to know your business and proposing the best fit for you in terms of features and budget, while never compromising on quality. We simply enjoy creating beautiful websites. Find out more about our services.&lt;/p&gt;
    &lt;p&gt;Do you require a world class corporate site, a friendly welcoming community site, or even something just plain funky? Whatever your design requirements, our design and development team caters for all audiences and markets. We have a wide range of designers at our disposal all from a variety of different design backgrounds, offering you a unique and beautifully designed website. &lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
</pre>
<h2>CSS</h2>
<pre class="brush: css">
h3.click_accordion {
	padding: 0;
	margin: 0 0 5px 0;
	background: url(../images/h2-bg.png) no-repeat;
	height: 46px;	line-height: 46px;
	width: 500px;
	font-size: 2em;
	font-weight: bold;
	float: left;
}

h3.click_accordion a {
	color: #fff;
	text-decoration: none;
	display: block;
	padding: 0 0 0 35px;
}

h3.click_accordion a:hover {
	background: url(../images/h2-bg.png) no-repeat;
	background-position: 0 -46px;
}

h3.active {
	background-position: 0 -92px;
}

.container_accordion {
	margin: 0 0 5px;
	padding: 0;
	overflow: hidden;
	font-size: 1.2em;
	width: 498px;
	clear: both;
	background: #f0f0f0;
	border: 1px solid #d6d6d6;
	-webkit-border-radius: 5px;
	-webkit-border-radius: 5px;
	-moz-border-radius: 5px;
	-moz-border-radius: 5px;
	border-bottom-right-radius: 5px;
	border-bottom-left-radius: 5px;
}
.container_accordion .content_accordion {
	padding: 20px;
}
</pre>
<h2>Setting up jQuery</h2>
<p>You can download jQuery from the jQuery site, or you can use the hosted one on Google.</p>
<pre class="brush: javascript">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Directly after you called your jQuery, start a new &lt;script&gt; tag and start your code by using the $(document).ready event.</p>
<pre class="brush: javascript">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){

//open/close settings -- set default
$(&#039;.container_accordion&#039;).hide(); //Hiding and closing the containers
$(&#039;.click_accordion:first&#039;).addClass(&#039;active&#039;).next().show(); //Add &quot;active&quot; class to first item, then show/open next container

//On/Click
$(&#039;.click_accordion&#039;).click(function(){
	if( $(this).next().is(&#039;:hidden&#039;) ) {
		$(&#039;.click_accordion&#039;).removeClass(&#039;active&#039;).next().slideUp();
		$(this).toggleClass(&#039;active&#039;).next().slideDown();
	}
	return false;
});

});
&lt;/script&gt;
</pre>
<p><a href="http://www.farajoomla.com/demos/jquery-accordion/" class="readmore"><span>View Demo</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.farajoomla.com/2010/05/accordion-with-jquery-and-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dropdown with jQuery and CSS</title>
		<link>http://www.farajoomla.com/2010/05/dropdown-mwith-jquery-and-css/</link>
		<comments>http://www.farajoomla.com/2010/05/dropdown-mwith-jquery-and-css/#comments</comments>
		<pubDate>Sun, 16 May 2010 21:42:37 +0000</pubDate>
		<dc:creator>Faramarz</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.farajoomla.com/?p=352</guid>
		<description><![CDATA[Here is a solution for a very simple drop down menu system. All you need is jQuery and these below few lines of JavaScript and CSS. The features of this menu system are: Unordered list as menu structure Absence of mouse events within html Timeout effect Cross-browser compatible (even IE 6) Multi-level and retains &#8220;trail&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a solution for a very simple drop down menu system. All you need is jQuery and these below few lines of JavaScript and CSS.</p>
<p>The features of this menu system are:</p>
<ul>
<li>Unordered list as menu structure</li>
<li> Absence of mouse events within html</li>
<li> Timeout effect</li>
<li> Cross-browser compatible (even IE 6)</li>
<li> Multi-level and retains &ldquo;trail&rdquo;</li>
<li> Easy to adopt styling</li>
<li> Minimal JavaScript</li>
</ul>
<h2>How to do it</h2>
<p>First thing you do is to include jQuery library (before &lt;/head&gt;)</p>
<pre class="brush: javascript">
&lt;script type=&#039;text/javascript&#039; src=&#039;http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js&#039;&gt;&lt;/script&gt;
</pre>
<p>I am using the jQuery library hosted on google codes, but you can download your own copy of jQuery and link it to your page.</p>
<p>Next step is to include the simple drop-down menu plugin. You can either include the code before &lt;/head&gt;, or save the code as an external JavaScript fine and include a link to it in your web page.</p>
<pre class="brush: javascript">
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){

    $(&quot;ul.dropdown li&quot;).hover(function(){

        $(this).addClass(&quot;hover&quot;);
        $(&#039;ul:first&#039;,this).css(&#039;visibility&#039;, &#039;visible&#039;);

    }, function(){

        $(this).removeClass(&quot;hover&quot;);
        $(&#039;ul:first&#039;,this).css(&#039;visibility&#039;, &#039;hidden&#039;);

    });

    $(&quot;ul.dropdown li ul li:has(ul)&quot;).find(&quot;a:first&quot;).append(&quot; &amp;amp;amp;amp;raquo; &quot;);

});
&lt;/script&gt;
</pre>
<p><strong>Note:</strong> if you are using as an external file, then you don&#8217;t need to enclose the code in  &lt;script type=&quot;text/javascript&quot;&gt; and &lt;/script&gt;.</p>
<p>Here is the HTML markup:</p>
<pre class="brush: html">
&lt;div id=&quot;page-wrap&quot;&gt;
        &lt;ul class=&quot;dropdown&quot;&gt;
        	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Business News&lt;/a&gt;
        		&lt;ul class=&quot;sub_menu&quot;&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Companies&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Economy&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;International&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;The Buzz&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;International&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;The Buzz&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;International&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;The Buzz&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Street Sweep&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Corrections&lt;/a&gt;&lt;/li&gt;
                     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Street Sweep&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Corrections&lt;/a&gt;&lt;/li&gt;
					 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Economy&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;International&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;The Buzz&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;International&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;The Buzz&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;International&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;The Buzz&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;
        		&lt;/ul&gt;
        	&lt;/li&gt;
        	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Markets&lt;/a&gt;
        		&lt;ul class=&quot;sub_menu&quot;&gt;
        			&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Pre-Market Training&lt;/a&gt;&lt;/li&gt;
        			&lt;li&gt;&lt;a href=&quot;#&quot;&gt;After Hours Training&lt;/a&gt;&lt;/li&gt;
        			&lt;li&gt;&lt;a href=&quot;#&quot;&gt;US Stocks&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Currencies&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Euro&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;US Dollar&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;British Pound&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Pre-Market Training&lt;/a&gt;&lt;/li&gt;
        			&lt;li&gt;&lt;a href=&quot;#&quot;&gt;After Hours Training&lt;/a&gt;&lt;/li&gt;
        			&lt;li&gt;&lt;a href=&quot;#&quot;&gt;US Stocks&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Currencies&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Euro&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;US Dollar&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;British Pound&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;
        		&lt;/ul&gt;
        	&lt;/li&gt;
        	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Personal Finance&lt;/a&gt;
        		&lt;ul class=&quot;sub_menu&quot;&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Money Magazine&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Real Estate&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Jobs&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Taxes&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Autos&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Jobs&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Taxes&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Autos&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Loan Center&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Best Places to Live&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Paris&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sweeden&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Ireland&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;
					 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Money Magazine&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Real Estate&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Jobs&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Taxes&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Autos&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Jobs&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Taxes&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Autos&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Loan Center&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;
        				&lt;a href=&quot;#&quot;&gt;Best Places to Live&lt;/a&gt;
        				&lt;ul&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Paris&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sweeden&lt;/a&gt;&lt;/li&gt;
        					&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Ireland&lt;/a&gt;&lt;/li&gt;
        				&lt;/ul&gt;
        			 &lt;/li&gt;

        		&lt;/ul&gt;
        	&lt;/li&gt;
        	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Technology&lt;/a&gt;
        		&lt;ul class=&quot;sub_menu&quot;&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Apple&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Google&lt;/a&gt;
						 &lt;ul&gt;
						 	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Gchat&lt;/a&gt;&lt;/li&gt;
							&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Ad Server&lt;/a&gt;&lt;/li&gt;
							&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Analytics&lt;/a&gt;&lt;/li&gt;
						 &lt;/ul&gt;
					 &lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Techmate&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;TechTalk&lt;/a&gt;&lt;/li&gt;
        		&lt;/ul&gt;
        	&lt;/li&gt;
        	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Preferences&lt;/a&gt;
        		&lt;ul class=&quot;sub_menu&quot;&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Login&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Register&lt;/a&gt;&lt;/li&gt;
        			 &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Account&lt;/a&gt;&lt;/li&gt;
        		&lt;/ul&gt;
        	&lt;/li&gt;
        &lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>And here is the CSS:</p>
<pre class="brush: css">
* 									{ margin: 0; padding: 0; }
#page-wrap							{ width: 100%; margin: 25px auto; }
a									{ text-decoration: none; }
ul									{ list-style: none; }
p                                   { margin: 15px 0; }
ul.dropdown                         { position: relative; }
ul.dropdown li                      { font-weight: bold; float: left; zoom: 1; background: #ccc; }
ul.dropdown a:hover		            { color: #000; }
ul.dropdown a:active                { color: #ffa500; }
ul.dropdown li a                    { display: block; padding: 4px 8px; border-right: 1px solid #333;
	 								  color: #222; }
ul.dropdown li:last-child a         { border-right: none; }
ul.dropdown li.hover,
ul.dropdown li:hover                { background: #F4B737; color: black; position: relative; }
ul.dropdown li.hover a              { color: black; }
ul.dropdown ul 						{ width: 220px; visibility: hidden; position: absolute; top: 100%; left: 0; }
ul.dropdown ul li 					{ font-weight: normal; background: #f6f6f6; color: #000;
									  border-bottom: 1px solid #ccc; float: none; }
ul.dropdown ul li a					{ border-right: none; width: 100%; display: inline-block; }
ul.dropdown ul ul 					{ left: 100%; top: 0; }
ul.dropdown li:hover &gt; ul 			{ visibility: visible; }
</pre>
<p>That&#8217;s it.</p>
<p><a href="http://www.farajoomla.com/demos/jquery-dropdown/" class="readmore"><span>View Demo</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.farajoomla.com/2010/05/dropdown-mwith-jquery-and-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How jQuery Works</title>
		<link>http://www.farajoomla.com/2010/05/how-jquery-works/</link>
		<comments>http://www.farajoomla.com/2010/05/how-jquery-works/#comments</comments>
		<pubDate>Tue, 04 May 2010 17:31:39 +0000</pubDate>
		<dc:creator>Faramarz</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.farajoomla.com/?p=214</guid>
		<description><![CDATA[In past JavaScript is used by developers for client side scripting, but now developers have several option to add the functionality of JavaScript by using other tool and libraries. jQuery is also one of the best libraries for adding javascript, ajax features in the application, although the same task can be performed through javascript but [...]]]></description>
			<content:encoded><![CDATA[<p>In past JavaScript is used by developers for client side scripting, but now developers have several option to add the functionality of JavaScript by using other tool and libraries. jQuery is also one of the best libraries for adding javascript, ajax features in the application, although the same task can be performed through javascript but jQuery provide the readymade easy to use functions.</p>
<h2>What is jQuery?</h2>
<p>jQuery is very rich library of functions and methods which does the same task like JavaScript but the difference is that jQuery is easy too use and give too much flexibility to the developers. The jQuery can be used in web application irrespective of the language or technology, it can be used with PHP,asp,jsp,servlets,CGI and almost all the programming languages.</p>
<p>The definition mentioned in jQuery official Web Site<br />
“jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript”</p>
<h2>The Basics</h2>
<p>This is a basic tutorial, designed to help you get started using jQuery.   If you don&#8217;t have a test page setup yet, start by creating a new HTML   page with the following contents:</p>
<pre class="brush: javascript">
&lt;!doctype html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;jquery.js&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot;&gt;

    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Edit the src attribute in the script tag to point to your   copy of jquery.js.  For example, if jquery.js is in the same directory as your HTML file,   you  can use: </p>
<pre class="brush: html">&lt;script type=&quot;text/javascript&quot; src=&quot;jquery.js&quot;&gt;&lt;/script&gt;</pre>
<h2> Launching Code on Document Ready </h2>
<p>The first thing that most Javascript programmers end up doing is   adding some code to their program, similar to this: </p>
<pre class="brush: javascript">window.onload = function(){ alert(&quot;welcome&quot;); }</pre>
<p>Inside of which is the code that you want to run right when the page   is loaded. Problematically, however, the Javascript code isn&#8217;t run until   all images are finished downloading (this includes banner ads). The   reason for using window.onload in the first place is that the HTML   &#8216;document&#8217; isn&#8217;t finished loading yet, when you first try to run your   code. </p>
<p>To circumvent both problems, jQuery has a simple statement that   checks the document and waits until it&#8217;s ready to be   manipulated, known as the <a href="http://docs.jquery.com/Events#ready.28_fn_.29" title="Events">ready   event</a>: </p>
<pre class="brush: javascript">
  $(document).ready(function(){
  // Your code here
  });
</pre>
<p>Inside the ready event, add a click handler to the link:</p>
<pre class="brush: javascript">
$(document).ready(function(){
  $(&quot;a&quot;).click(function(event){
  alert(&quot;Thanks for visiting!&quot;);
  });
  });
</pre>
<p>Save your HTML file and reload the test page in your browser. Clicking the link on the page should make a browser&#8217;s alert pop-up, before leaving to go to the main jQuery page.</p>
<p>For click and most other events, you can prevent the default behaviour &#8211; here, following the link to jquery.com &#8211; by calling event.preventDefault() in the event handler:</p>
<pre class="brush: javascript">
$(document).ready(function(){
  $(&quot;a&quot;).click(function(event){
  alert(&quot;As you can see, the link no longer took you to jquery.com&quot;);
  event.preventDefault();
  });
  });
</pre>
<p><strong> Complete Example</strong></p>
<p>The following is an example of what the complete HTML file might look like if you were to use the script in your own file. Note that it links to Google&#8217;s CDN to load the jQuery core file. Also, while the custom script is included in the &lt;head&gt;, it is generally preferable to place it in a separate file and refer that file with the script element&#8217;s src attribute</p>
<pre class="brush: html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
$(&quot;a&quot;).click(function(event){
alert(&quot;As you can see, the link no longer took you to jquery.com&quot;);
event.preventDefault();
});
});

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p> Adding and Removing an HTML Class</p>
<p>Important: The remaining jQuery examples will need to be placed inside the ready event so that they are executed when the document is ready to be worked on. See Launching Code on Document Ready above for details.</p>
<p>Another common task is adding (or removing) a class.</p>
<p>First, add some style information into the &lt;head&gt; of your document, like this:</p>
<pre class="brush: css">
&lt;style type=&quot;text/css&quot;&gt;
	a.test { font-weight: bold; }
&lt;/style&gt;
[sourcecode]
&lt;p&gt;Next, add the addClass call to your script:&lt;/p&gt;
[sourcecode language=&#039;javascript&#039;]$(&quot;a&quot;).addClass(&quot;test&quot;);</pre>
<p>All your a elements will now be bold.</p>
<p>To remove the class, use removeClass</p>
<pre class="brush: javascript">$(&quot;a&quot;).removeClass(&quot;test&quot;);</pre>
<p> * (HTML allows multiple classes to be added to an element.) </p>
<h2> Special Effects</h2>
<p>In jQuery, a couple of handy effects are provided, to really make your web site stand out. To put this to the test, change the click that you added earlier to this:</p>
<pre class="brush: javascript">
$(&quot;a&quot;).click(function(event){
   event.preventDefault();
   $(this).hide(&quot;slow&quot;);
 });
</pre>
<p>Now, if you click any link, it should make itself slowly disappear.</p>
<h2>Callback and Functions</h2>
<p>A callback is a function that is passed as an argument to another function and is executed after its parent function has completed. The special thing about a callback is that functions that appear after the &quot;parent&quot; can execute before the callback executes.</p>
<p>Another important thing to know is how to properly pass the callback. This is where I have often forgotten the proper syntax.</p>
<h2>Callback without arguments</h2>
<p>For a callback with no arguments you pass it like this:</p>
<pre class="brush: javascript"> $.get(&#039;myhtmlpage.html&#039;, myCallBack);</pre>
<p><strong>Note</strong> that the second parameter here is simply the function name (but not as a string and without parentheses). Functions in Javascript are &#8216;First class citizens&#8217; and so can be passed around like variable references and executed at a later time.</p>
<h2>Callback with arguments</h2>
<p>&quot;What do you do if you have arguments that you want to pass?&quot;, you might ask yourself.</p>
<p> Wrong</p>
<p>The Wrong Way (will not work!)</p>
<pre class="brush: javascript"> $.get(&#039;myhtmlpage.html&#039;, myCallBack(param1, param2));</pre>
</p>
<p>This will not work because it calls</p>
<p>myCallBack(param1, param2)</p>
<p>and then passes the return value as the second parameter to $.get().</p>
<p> Right</p>
<p>The problem with the above example is that myCallBack(param1, param2) is evaluated before being passed as a function. Javascript and by extension jQuery expects a function pointer in cases like these. I.E. setTimeout function.</p>
<p>In the below usage, an anonymous function is created (just a block of statements) and is registered as the callback function. Note the use of &#8216;function(){&#8216;. The anonymous function does exactly one thing: calls myCallBack, with the values of param1 and param2 in the outer scope.</p>
<pre class="brush: javascript">
$.get(&#039;myhtmlpage.html&#039;, function(){
  myCallBack(param1, param2);
  });
</pre>
<p>param1 and param2 are evaluated as a callback when the &#8216;$.get&#8217; is done getting the page. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.farajoomla.com/2010/05/how-jquery-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

