<?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>Six Revisions &#187; JavaScript</title>
	<atom:link href="http://sixrevisions.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixrevisions.com</link>
	<description></description>
	<lastBuildDate>Thu, 02 Sep 2010 10:30:49 +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>The Power of jQuery with Ajax</title>
		<link>http://sixrevisions.com/javascript/the-power-of-jquery-with-ajax/</link>
		<comments>http://sixrevisions.com/javascript/the-power-of-jquery-with-ajax/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 16:35:15 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3522</guid>
		<description><![CDATA[
As the web evolves, new technologies are emerging and uniting in remarkable ways. The combination of Ajax and jQuery, in particular, is one of the most powerful unions to date.
The purpose of this article is to give a brief and generalized overview of both Ajax and jQuery, and also discuss how jQuery has made Ajax [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/javascript/the-power-of-jquery-with-ajax/"><img src="http://images.sixrevisions.com/2010/06/23-01_jquery_ajax_ld_img.jpg" width="550" height="200" alt="The Power of jQuery with Ajax" /></a></p>
<p>As the web evolves, new technologies are emerging and uniting in remarkable ways. The combination of Ajax and jQuery, in particular, is one of the most powerful unions to date.</p>
<p>The purpose of this article is to give a brief and generalized overview of both Ajax and jQuery, and also discuss how jQuery has made Ajax development easier than ever before.</p>
<p><span id="more-3522"></span></p>
<h3>What is Ajax?</h3>
<p>Since its conception in 2005<sup>[<a href="#reference-01">1</a>]</sup>, Ajax (Asynchronous JavaScript and XML) has changed the web as we know it today. It&#8217;s helped websites evolve into Rich Internet Applications (RIAs) by allowing web pages to make direct requests to web servers without reloading the page. This capability is vital in replicating the rich user experiences achieved in client applications.</p>
<h4>Ajax in Practice</h4>
<p>Let&#8217;s say that you have a login form for your web application. To ensure that the provided login name and password entered by the user is a match without using Ajax, your web application would have to load a whole new web page that shows an account screen if the login was successful, or show an error screen if the login failed. This is the old way of handling logins.</p>
<p>A <strong>more savvy approach</strong> to this problem would be to check if the login and password is correct using Ajax.</p>
<p>Here&#8217;s how Ajax would work in this instance: Once the user has typed in a login name and password and submitted the login web form, you could have a JavaScript function that invokes an Ajax call that sends two parameters — the login name and password.</p>
<p>The web server (usually through a server-side script/language such as PHP) takes the two parameters and then queries your user database to see if there is a match.</p>
<p>If there is a match found in your database, then the web server can return a success flag. Otherwise, the web server could return an error message.</p>
<p>Next, you would then have a JavaScript function that accepts the Ajax response. If the response is successful, it could use <code>window.location</code> to send the user to their account screen.</p>
<p>If the response contains an error message, the application can display the error on the screen without ever reloading the page.</p>
<p>The main thing to take away from this is that you don&#8217;t have to reload an entire page just to handle username/password verification, making your web application more responsive and, if the page is heavy, saving you some significant bandwidth.</p>
<h3>What is jQuery?</h3>
<p>Released in January of 2006<sup>[<a href="#reference-02">2</a>]</sup>, <a href="http://sixrevisions.com/javascript/getting-started-with-jquery/" title="Getting Started with jQuery - sixrevisions.com">jQuery</a> is a cross-browser JavaScript library designed to simplify the client-side script of HTML.</p>
<p>Used by close to a million websites<sup>[<a href="#reference-03">3</a>]</sup>, jQuery is the most popular JavaScript library in use to date.</p>
<p>jQuery makes it easy to handle DOM objects, events, effects and Ajax, automatically takes care of JavaScript leaks, and has countless third-party plugins.</p>
<h3>The Problem with Ajax</h3>
<p>Despite its revolutionary impact on the web, Ajax can be difficult to use even for veteran developers.</p>
<p>People will usually create their own custom functions to handle Ajax calls so that the functionality can be reused across a web application. This can become very tedious when a web application makes use of different types of Ajax calls — such as the ability to handle both synchronous and asynchronous calls — or the ability to handle different response formats such as string messages, HTML, CSV, XML, JSON, etc.</p>
<p>As a professional web developer, I&#8217;ve personally spent countless hours building custom methods to handle Ajax calls. </p>
<p>Traditional Ajax calls usually take on the following form:</p>
<pre>
function httpRequest(id) {
  if (window.XMLHttpRequest) { // code for IE7+, FF, Chrome, Opera, Safari
    http=new XMLHttpRequest();
  }
  else { // code for IE6, IE5
    http=new ActiveXObject(&quot;Microsoft.XMLHTTP”);
  }
  http.onreadystatechange=function() {
    if (http.readyState==4 &amp;&amp; http.status==200) {
      response = http.responseText;
      // do something with response
    }
  }
  dest=”servlet.php?id=” + id;
  http.open(&quot;GET”, dest);
  http.send();
}</pre>
<p>If your web application only uses one Ajax call, it&#8217;s not that big of a deal to implement. The problem occurs, however, when your web application leverages lots of Ajax calls and you try to break the code apart to make it reusable.</p>
<p>The idea of Ajax is to send a request to some web server, wait for a response, and update your HTML page. It would be convenient to create a custom function like <code>httpRequest()</code> that takes two parameters — a request URL and a response function — that could be reused throughout your system.</p>
<p>Once you start setting this up, however, you&#8217;ll immediately see that the simple task of making an Ajax call suddenly becomes a nightmare when you try to construct response function evaluations using <code>eval()</code> and figuring out how to make your new function handle synchronous calls, asynchronous calls, and different response formats.</p>
<p>At the end of the day, the simple idea of creating a custom <code>httpRequest()</code> function quickly turns into a big project.</p>
<p>The other advantage of jQuery is that it has additional Ajax functions and methods that you can use, which can further reduce development and debugging time.</p>
<h3>Hello Ajax. Meet jQuery.</h3>
<p>Among other advantages, one of my favorite features of jQuery is its ability to leverage Ajax with very little effort. To make an Ajax call, you can do something like this:</p>
<pre>$.Ajax({
  type: &quot;POST&quot;,
  url: &quot;some.php&quot;,
  data: &quot;name=John&amp;location=Boston&quot;,
  success: function(msg){
    alert( &quot;Data Saved: &quot; + msg );
  }
});</pre>
<p>If you&#8217;ve developed Ajax applications before without jQuery, you&#8217;ll immediately see the value here. jQuery has put all of the properties of Ajax into one simple API. You can control everything including the <code>url</code>, <code>cache</code>, success function, data type, and even synchronization, all from one neat declaration. It&#8217;s nothing short of beautiful.</p>
<h3>Get Started with Ajax + jQuery</h3>
<p>If you&#8217;re not using a JavaScript Web Development framework like jQuery or MooTools yet, and you&#8217;re planning on creating responsive web applications, you should leverage these awesome libraries.</p>
<p>For jQuery, the following list highlights some tutorials you can check out.</p>
<ul>
<li><a href="http://www.bitrepository.com/a-simple-ajax-contact-form-with-php-validation.html">AJAX Contact Form without page reload</a></li>
<li><a href="http://articles.sitepoint.com/article/ajax-jquery">Easy Ajax with jQuery</a></li>
<li><a href="http://net.tutsplus.com/tutorials/javascript-ajax/how-to-load-in-and-animate-content-with-jquery/">How to Load In and Animate Content with jQuery</a></li>
</ul>
<h3>References</h3>
<ol>
<li id="#reference-01"><a href="http://www.adaptivepath.com/ideas/essays/archives/000385.php">Ajax: A New Approach to Web Applications</a></li>
<li id="#reference-02"><a href="http://blog.jquery.com/2006/08/26/jquery-10/">jQuery 1.0</a></li>
<li id="#reference-03"><a href="http://trends.builtwith.com/javascript/JQuery">jQuery Usage Statistics</a></li>
</ol>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/javascript/getting-started-with-jquery/">Getting Started with jQuery</a></li>
<li><a href="http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/">Create a Slick and Accessible Slideshow Using jQuery</a></li>
<li><a href="http://sixrevisions.com/javascript/10-easy-jquery-tricks-for-designers/">10 Easy jQuery Tricks for Designers</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/eric_rowell_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Eric Rowell</strong> is a professional web developer and designer who is fascinated with everything related to the web, including RIAs, emerging technology, and social media marketing. He is the Founder and Chief Editor of <a href="http://www.webkrunk.com/"><strong>Web Krunk</strong></a> and loves HTML, HTML5, CSS, JavaScript, Ajax, jQuery, Flash, PHP and Java. You can follow him on Twitter at <strong>@<a href="http:/twitter.com/webkrunk">webkrunk</a>.</strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/the-power-of-jquery-with-ajax/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>20 Fresh JavaScript Data Visualization Libraries</title>
		<link>http://sixrevisions.com/javascript/20-fresh-javascript-data-visualization-libraries/</link>
		<comments>http://sixrevisions.com/javascript/20-fresh-javascript-data-visualization-libraries/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 14:05:40 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=2393</guid>
		<description><![CDATA[This article presents twenty JavaScript libraries that you can use to bring your data to life.]]></description>
			<content:encoded><![CDATA[<p>There are plenty of JavaScript libraries out there for rendering your otherwise plain and boring numerical data into beautiful, interactive, and informative visualizations. The beauty of using JavaScript for data visualization is that, if created correctly, your data will be highly accessible (usually via HTML tables). A long time ago (2008), I wrote about <a href="http://sixrevisions.com/javascript/graph_chart_plot_data_javascript/">JavaScript solutions for graphing and charting data</a> and this article revisits the topic with twenty more JavaScript libraries that you can use to bring your data to life.</p>
<h3>1. <a href="http://highcharts.com/">Highcharts</a></h3>
<p><a href="http://highcharts.com/"><img src="http://images.sixrevisions.com/2010/01/18-01_highcharts.png" width="550" height="270" alt="Highcharts" /></a></p>
<p><span id="more-2393"></span></p>
<p><em>Highcharts</em> is one of the most promising JavaScript charting libraries to hit the scene recently, with its large array of features including seven charting types (line, pie, and bar among them),  the ability to zoom in and out of charts, and tooltips for offering more information about data points. The library has many options for customization and they&#8217;re <a href="http://www.highcharts.com/ref/#chart">well documented on one page</a> for easy referencing.</p>
<ul>
<li><a href="http://highcharts.com/demo/">Highcharts Demo</a></li>
<li><a href="http://highcharts.com/download">Highcharts Download</a></li>
</ul>
<h3>2. <a href="http://g.raphaeljs.com/">gRaphaël</a></h3>
<p><a href="http://g.raphaeljs.com/"><img src="http://images.sixrevisions.com/2010/01/18-02_graphael.jpg" width="550" height="270" alt="gRaphaël" /></a></p>
<p><em>gRaphaël</em> is a charting library based on <a href="http://raphaeljs.com/">Raphaël</a>, a vector graphics drawing JavaScript library. The library is divided into sub-libraries so that you can just download the type of chart that you&#8217;re interesting in creating. With the main library, g.raphael.js, at only 12KB and sub-libraries between 4KB to 8KB, this can be a lightweight but fully featured JavaScript charting solution for web developers.</p>
<ul>
<li><a href="http://g.raphaeljs.com/barchart.html">gRaphaël Demo</a></li>
<li><a href="http://g.raphaeljs.com/">gRaphaël Download</a></li>
</ul>
<h3>3. <a href="http://thejit.org/">JavaScript InfoVis Toolkit</a></h3>
<p><a href="http://thejit.org/"><img src="http://images.sixrevisions.com/2010/01/18-03_infovis.jpg" width="550" height="270" alt="JavaScript InfoVis Toolkit" /></a></p>
<p><em>JavaScript InfoVis</em>, a charting library influenced partly by MooTools, is a robust and excellent solution for data visualization. It&#8217;s modular (just like MooTools) so that you can include just the parts you need to keep your pages light. It has animation effects capability to captivate and engage your users, plenty of charting types, a helper class for working with JSON data, and much more.</p>
<ul>
<li><a href="http://thejit.org/demos/">JavaScript InfoVis Toolkit Demo</a></li>
<li><a href="http://thejit.org/">JavaScript InfoVis Toolkit Download</a></li>
</ul>
<h3>4. <a href="http://www.filamentgroup.com/lab/jquery_visualize_plugin_accessible_charts_graphs_from_tables_html5_canvas/">jQuery Visualize Plugin</a></h3>
<p><a href="http://www.filamentgroup.com/lab/jquery_visualize_plugin_accessible_charts_graphs_from_tables_html5_canvas/"><img src="http://images.sixrevisions.com/2010/01/18-04_jquery_visualize.png" width="550" height="270" alt="jQuery Visualize Plugin" /></a></p>
<p>If you&#8217;re already using jQuery, it&#8217;d be performance conscious of you to look into plugins for your visualization requirements. <em>jQuery Visualize</em>, a plugin developed by the Filament Group (the core developers of <a href="http://www.filamentgroup.com/portfolio/jquery_ui_and_themeroller/">jQuery UI</a>), is a jQuery plugin for generating charts using HTML5&#8217;s canvas element. It has 14 options for customizing your charts. Don&#8217;t forget to try out their <a href="http://www.filamentgroup.com/examples/charting_v2/index_2.php">Configurable demo</a>.</p>
<ul>
<li><a href="http://www.filamentgroup.com/examples/charting_v2/">jQuery Visualize Plugin Demo</a></li>
<li><a href="http://www.filamentgroup.com/lab/jquery_visualize_plugin_accessible_charts_graphs_from_tables_html5_canvas/">jQuery Visualize Plugin Download</a></li>
</ul>
<h3>5. <a href="http://moochart.coneri.se/">moochart</a></h3>
<p><a href="http://moochart.coneri.se/"><img src="http://images.sixrevisions.com/2010/01/18-05_moochart.png" width="550" height="270" alt="moochart" /></a></p>
<p>For now, <em>moochart</em> only plots <a href="http://moochart.coneri.se/#demo" title="Demo showing what a bubble diagram is.">bubble diagrams</a>, but there are plans to expand this MooTools 1.2 plugin to feature pie, line, and bar graphs. The plugin has 14 options that you can use for customizing your diagram&#8217;s look, and tooltips for providing more information about a bubble when mousing over them. <em>moochart</em> is open source and released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</p>
<ul>
<li><a href="http://moochart.coneri.se/#demo">moochart Demo</a></li>
<li><a href="http://moochart.coneri.se/#download">moochart Download</a></li>
</ul>
<h3>6. <a href="http://www.jscharts.com/">JS Charts</a></h3>
<p><a href="http://www.jscharts.com/"><img src="http://images.sixrevisions.com/2010/01/18-06_js_charts.png" width="550" height="270" alt="JS Charts" /></a></p>
<p><em>JS Charts</em> boasts easy usage by emphasizing on the end-user&#8217;s ability to use the library with little to no coding, making it ideal for web designers who&#8217;d like to chart data without spending too much time learning how to write JavaScript. JS Charts has a web-based GUI and offers hosting for your charts to take some load off your own servers. It supports three chart types: bar, pie, and line.</p>
<ul>
<li><a href="http://www.jscharts.com/examples">JS Charts Demo</a></li>
<li><a href="http://www.jscharts.com/examples">JS Charts Download</a></li>
</ul>
<h3>7. <a href="http://www.danvk.org/dygraphs/">dygraphs</a></h3>
<p><a href="http://www.danvk.org/dygraphs/"><img src="http://images.sixrevisions.com/2010/01/18-07_dygraphs.png" width="550" height="270" alt="dygraphs" /></a></p>
<p><em>dygraphs</em> is a JavaScript library for producing interactive charts for time series data. It was designed to plot dense data sets (such as temperature fluctuations). It has user interfacing options such giving the user the ability to specify time intervals on the fly, displaying of values when mousing over parts of the chart, and zooming. It also integrates with the <a href="http://code.google.com/apis/visualization/">Google Visualization API</a>.</p>
<ul>
<li><a href="http://www.danvk.org/dygraphs/tests/">dygraphs Demo</a></li>
<li><a href="http://github.com/danvk/dygraphs/downloads/">dygraphics Downloads</a></li>
</ul>
<h3>8. <a href="http://jsxgraph.uni-bayreuth.de/wp/">JSXGraph</a></h3>
<p><a href="http://jsxgraph.uni-bayreuth.de/wp/"><img src="http://images.sixrevisions.com/2010/01/18-08_jsxgraph.png" width="550" height="270" alt="JSXGraph" /></a></p>
<p><em>JSXGraph</em>, developed at the University of Bayreuth in Germany, is a standalone JavaScript library for plotting complex geometric shapes and data such as Bezier curves, differential equations, and much more. It has animation features for moving graphs, interactive components such as sliders for experimenting with changing values of variables, and <a href="http://jsxgraph.uni-bayreuth.de/wiki/index.php/Category:Charts">plenty of charting types</a> to choose from.</p>
<ul>
<li><a href="http://jsxgraph.uni-bayreuth.de/wp/examples/">JSXGraph Demo</a></li>
<li><a href="http://jsxgraph.uni-bayreuth.de/wp/download/">JSXGraph Download</a></li>
</ul>
<h3>9. <a href="http://www.deensoft.com/lab/protochart/index.php">Protochart</a></h3>
<p><a href="http://www.deensoft.com/lab/protochart/index.php"><img src="http://images.sixrevisions.com/2010/01/18-09_protochart.png" width="550" height="270" alt="Protochart" /></a></p>
<p><em>Protochart</em> is a JavaScript library for use with the Prototype JS framework. It uses HTML5&#8217;s canvas for modern browsers, and the <a href="http://excanvas.sourceforge.net/">ExCanvas library</a> for Internet Explorer support. It has six types of charts including line, pie, bars, points, lines with points, and area graphs. It allows for the display of legends that are highly configurable to help identify items on your charts.</p>
<ul>
<li><a href="http://www.deensoft.com/lab/protochart/piechart.php">Protochart Demo</a></li>
<li><a href="http://www.deensoft.com/lab/protochart/index.php">Protochart Download</a></li>
</ul>
<h3>10. <a href="http://bluff.jcoglan.com/">Bluff</a></h3>
<p><a href="http://bluff.jcoglan.com/"><img src="http://images.sixrevisions.com/2010/01/18-10_bluff.png" width="550" height="270" alt="Bluff" /></a></p>
<p><em>Bluff</em> is a lightweight charting library that ports Ruby&#8217;s <a href="http://nubyonrails.com/pages/gruff">Gruff</a> gem to JavaScript. Weighing at only 11KB gzip&#8217;ed (you also need JS.Class which only weighs 2.6KB gzip&#8217;ed), it&#8217;s surprising that you&#8217;ll be able to get 15 different types of charts out of this library. It features tooltips, a ton of configurable options, legend support, and the .set_theme method for declaring reusable themes.</p>
<ul>
<li><a href="http://bluff.jcoglan.com/">Bluff Demo</a></li>
<li><a href="http://bluff.jcoglan.com/">Bluff Download</a></li>
</ul>
<h3>11. <a href="http://chart.inetsoft.com/">Style Chart</a></h3>
<p><a href="http://chart.inetsoft.com/"><img src="http://images.sixrevisions.com/2010/01/18-11_style_charts.png" width="550" height="270" alt="Style Chart" /></a></p>
<p><em>Style Chart</em> is a free JavaScript-based charting web service/API for creating hosted charts. It&#8217;s also available as a downloadable library in case you want to host your own charts (though you need to register in order to download it). It has the things you&#8217;d expect from a robust and configurable charting library such as tooltips, legends, and 19 types of charts including 3D pie, 3D bar graphs and Pareto charts.</p>
<ul>
<li><a href="http://chart.inetsoft.com/gallery.html">Style Chart Demos</a></li>
<li><a href="http://chart.inetsoft.com/download.html">Style Chart Download</a></li>
</ul>
<h3>12. <a href="http://www.jqplot.com/">jqPlot</a></h3>
<p><a href="http://www.jqplot.com/"><img src="http://images.sixrevisions.com/2010/01/18-12_jqplot.png" width="550" height="270" alt="jqPlot" /></a></p>
<p><em>jqPlot</em> is another jQuery plugin for data visualization developed by Chris Leonello. It&#8217;s open source, embodying two sets of licensing: MIT and GPL version 2. It has <a href="http://www.jqplot.com/docs/files/optionsTutorial-txt.html">many options</a> for you to take advantage of in order to truly customize your charts.</p>
<ul>
<li><a href="http://www.jqplot.com/tests/">jqPlot Demos</a></li>
<li><a href="http://bitbucket.org/cleonello/jqplot/downloads/">jqPlot Download</a></li>
</ul>
<h3>13. <a href="http://omnipotent.net/jquery.sparkline/">jQuery Sparklines</a></h3>
<p><a href="http://omnipotent.net/jquery.sparkline/"><img src="http://images.sixrevisions.com/2010/01/18-13_jquery_sparklines.png" width="550" height="270" alt="jQuery Sparklines" /></a></p>
<p><em>jQuery Sparklines</em> is a simple and lightweight jQuery plugin for charting dynamic <a href="http://en.wikipedia.org/wiki/Sparkline">sparklines</a> (a condensed data graphic). It emphasizes on ease of use and minimal coding; you can create complex sparklines with as little as one line of JavaScript code. When minified and gzip&#8217;ed, the plugin only weights 4.7KB so it won&#8217;t bog down your page response times much.</p>
<ul>
<li><a href="http://omnipotent.net/jquery.sparkline/#examples">jQuery Sparklines Demos</a></li>
<li><a href="http://omnipotent.net/jquery.sparkline/">jQuery Sparklines Download</a></li>
</ul>
<h3>14. <a href="http://www.maxb.net/scripts/jgcharts/include/demo/">jQuery Google Charts</a></h3>
<p><a href="http://www.maxb.net/scripts/jgcharts/include/demo/"><img src="http://images.sixrevisions.com/2010/01/18-14_jgcharts.png" width="550" height="270" alt="jQuery Google Charts" /></a></p>
<p><em>jQuery Google Charts</em> (abbreviated as jGCharts), developed by Massimiliano Balestrieri, is a data visualization jQuery plugin for working with the <a href="http://code.google.com/apis/chart/">Google Charts API</a>. It has plenty of chart types, including a 3D pie chart that&#8217;s dynamically generated. It has a <a href="http://www.maxb.net/scripts/jgcharts/include/gui/">GUI in development</a> (still in alpha release), which will allow you to create charts easily with a graphical front-end.</p>
<ul>
<li><a href="http://www.maxb.net/scripts/jgcharts/include/demo/">jQuery Google Charts Demo</a></li>
<li><a href="http://www.maxb.net/scripts/jgcharts/include/demo/">jQuery Google Charts Download</a></li>
</ul>
<h3>15. <a href="http://blog.greghoustondesign.com/canvas-pie-chart-with-tooltips/">Canvas Pie Chart with Tooltips</a></h3>
<p><a href="http://blog.greghoustondesign.com/canvas-pie-chart-with-tooltips/"><img src="http://images.sixrevisions.com/2010/01/18-15_canvas_pie.png" width="550" height="270" alt="Canvas Pie Chart with Tooltips" /></a></p>
<p>This MooTools class/plugin is for plotting pie charts using the canvas element. It&#8217;s based on <a href="http://www.phpied.com/canvas-pie/">Canvas pie</a> by Stoyan Stefanov. It&#8217;s a simple and straightforward data visualization option for MooTools developers who are only interested in plotting out pie charts.</p>
<ul>
<li><a href="http://demos.greghoustondesign.com/piechart/">Canvas Pie Chart with Tooltips Demo and Download</a></li>
</ul>
<h3>16. <a href="http://xaviershay.github.com/tufte-graph/">TufteGraph</a></h3>
<p><a href="http://xaviershay.github.com/tufte-graph/"><img src="http://images.sixrevisions.com/2010/01/18-16_tuftegraph.png" width="550" height="270" alt="TufteGraph" /></a></p>
<p><em>TufteGraph</em> is a jQuery plugin that emphasizes on ease of use and minimalism. It offers you only a few options for styling and instead relies on CSS for customizing the look and feel of your graphs, which ultimately means that your web pages will render faster because JS has to work less. Check out this <a href="http://vimeo.com/2655244" title="Introduction to TufteGraph on Vimeo">introduction video to TufteGraph</a>.</p>
<ul>
<li><a href="http://xaviershay.github.com/tufte-graph/">TufteGraph Demo</a></li>
<li><a href="http://xaviershay.github.com/tufte-graph/">TufteGraph Download</a></li>
</ul>
<h3>17. <a href="http://www.simile-widgets.org/timeline/">Timeline</a></h3>
<p><a href="http://www.simile-widgets.org/timeline/"><img src="http://images.sixrevisions.com/2010/01/18-17_timeline.jpg" width="550" height="270" alt="Timeline" /></a></p>
<p><em>Timeline</em> is a JavaScript widget for creating interactive timelines. You can scroll through items featured in chronological order by using your mousewheel or by holding down your mouse button on the timeline and dragging left or right. Clicking on a dot, which represents an item in the time line, will reveal more information. Timeline is open source, released under the <a href="http://simile.mit.edu/license.html">BSD license</a>.</p>
<ul>
<li><a href="http://www.simile-widgets.org/timeline/examples/index.html">Timeline Demos</a></li>
<li><a href="http://code.google.com/p/simile-widgets/downloads/list">Timeline Download</a></li>
</ul>
<h3>18. <a href="http://vis.stanford.edu/protovis/">Protovis</a></h3>
<p><a href="http://vis.stanford.edu/protovis/"><img src="http://images.sixrevisions.com/2010/01/18-18_protovis.png" width="550" height="270" alt="Protovis" /></a></p>
<p><em>Protovis</em> is a data visualization library for charting data. Protovis was created by the <a href="http://vis.stanford.edu/">Stanford Visualization Group</a>. It uses JavaScript and SVG to dynamically plot out your data. Protovis is open source released under the <a href="http://www.opensource.org/licenses/bsd-license.php">BSD license</a>. You can download the source on their home page.</p>
<ul>
<li><a href="http://vis.stanford.edu/protovis/ex/">Protovis Demos</a></li>
</ul>
<h3>19. <a href="http://code.google.com/p/milkchart/">milkchart</a></h3>
<p><a href="http://code.google.com/p/milkchart/"><img src="http://images.sixrevisions.com/2010/01/18-19_milkchart.png" width="550" height="270" alt="milkchart" /></a></p>
<p><em>milkchart</em> is a JavaScript charting/graphing library that requires MooTools. milkchart renders HTML data tables into one of its five types of charts: column, bar, line, scatter, and pie (with future expansions planned for area graphs) using HTML5&#8217;s Canvas element. milkchart is open source under <a href="http://www.apache.org/licenses/LICENSE-2.0">the Apache License</a>.</p>
<ul>
<li><a href="http://code.google.com/p/milkchart/downloads/list">milkchart Download</a></li>
</ul>
<h3>20. <a href="http://www.simile-widgets.org/timeplot/">Timeplot</a></h3>
<p><a href="http://www.simile-widgets.org/timeplot/"><img src="http://images.sixrevisions.com/2010/01/18-20_timeplot.png" width="550" height="270" alt="Timeplot" /></a></p>
<p><em>Timeplot</em> allows you to dynamically generate time series graphs. Hovering over data points reveals their value. Timeplot was developed as part of the <a href="http://simile.mit.edu/">SIMILE Project</a> at MIT. Here&#8217;s a <a href="http://www.simile-widgets.org/timeplot/docs/">step-by-step tutorial on how to utilize Timeplot</a>. Timeplot is open source and available the <a href="http://simile.mit.edu/license.html">BSD license</a>. The Timeplot demo and download links are on this page.</p>
<ul>
<li><a href="http://www.simile-widgets.org/timeplot/">Timeplot Demos and Download Info</a></li>
</ul>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/javascript/graph_chart_plot_data_javascript/">Graphing/Charting Data on Web Pages: JavaScript Solutions</a></li>
<li><a href="http://sixrevisions.com/javascript/promising_javascript_frameworks/">10 Promising JavaScript Frameworks</a></li>
<li><a href="http://sixrevisions.com/javascript/10-impressive-javascript-animation-frameworks/">10 Impressive JavaScript Animation Frameworks</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/jacob_gube_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Jacob Gube</strong> is the Founder and Chief Editor of <strong><a href="http://sixrevisions.com/">Six Revisions</a></strong>. He&#8217;s also a web developer/designer who specializes in front-end development (JavaScript, HTML, CSS) and PHP development. If you&#8217;d like to connect with him, head on over to the <a href="http://sixrevisions.com/contact/">contact page</a> and follow him on Twitter: <strong>@<a href="http://twitter.com/sixrevisions">sixrevisions</a></strong>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/20-fresh-javascript-data-visualization-libraries/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Getting Started with jQuery</title>
		<link>http://sixrevisions.com/javascript/getting-started-with-jquery/</link>
		<comments>http://sixrevisions.com/javascript/getting-started-with-jquery/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 18:02:10 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=2149</guid>
		<description><![CDATA[In this article, I'll be introducing and laying the groundwork for advanced JavaScript development with one of the most popular JavaScript libraries available: jQuery.]]></description>
			<content:encoded><![CDATA[<p>The web development scene is moving forward at a lightning-fast  pace, and it&#8217;s imperative that developers continue to keep their  skills fresh. If you&#8217;ve been involved in front-end design or  development in any form over the past five years or so, then it&#8217;s very  likely that you&#8217;ve experimented at some point with one of the popular  JavaScript libraries, many of which have become quite prominent and are  now used on a number of large commercial websites.</p>
<p><img src="http://images.sixrevisions.com/2009/12/13-01_jquery_getting_started_lead_image.jpg" width="550" height="250" alt="Getting Started with jQuery" /></p>
<p><span id="more-2149"></span></p>
<p>In this article, I&#8217;ll be introducing and laying the groundwork for  advanced JavaScript development with one of the most popular JavaScript  libraries available: <a href="http://jquery.com">jQuery</a>.</p>
<p>Although there are many beginning tutorials online that can provide a  great starting point for jQuery development, in this article I&#8217;m hoping  to go beyond just quick-start syntax and instead provide a solid  overview of jQuery and discuss the benefits of using such a library. Of  course, much of this information&#8211;outside of the syntax and other  jQuery-specific details&#8211;will be applicable to any JavaScript library.</p>
<h3>Why a JavaScript library?</h3>
<p>To quote the official jQuery slogan: &quot;Write less, do more.&quot; The role  of a web developer is to create code that determines what will result  from a user&#8217;s interaction with a web page. Web developers should not  have to spend hours debugging browser quirks. Instead, they should be  free to deal solely with the actions and the results. This is where a JavaScript library comes into play.</p>
<h4>Overcoming browser differences</h4>
<p>Different browsers handle DOM manipulation, transparency effects,  and animation in different ways, requiring, in some cases, reams of  code just to create a simple effect. Using a JavaScript library allows  you to completely bypass all of those challenges, giving you access to  an API (Application Programming Interface) that deals directly with the  tasks you actually want to accomplish. All the challenges and issues  common to JavaScript are dealt with behind the scenes, allowing you  to integrate functionality without wondering whether or not it will  work in a particular browser.</p>
<h4>Unobtrusive JavaScript</h4>
<p>Another impelling reason to use a JavaScript library is that all  libraries allow you to include JavaScript in your pages unobtrusively,  thus keeping your <em>behavior</em> layer (the JavaScript) separate from the <em>content</em> and <em>presentation</em> layers (the XHTML and CSS).</p>
<h4>Accomplishing complex tasks with ease</h4>
<p>Finally, a very powerful feature of any JavaScript library is its  ability to manipulate any element or set of elements on a web page with  just one line of code. Take, for example, the following HTML:</p>
<pre>&lt;div class=&quot;container&quot;&gt;
  &lt;ul class=&quot;list&quot;&gt;
    &lt;li&gt;Text Here&lt;/li&gt;
    &lt;li&gt;Text Here&lt;/li&gt;
    &lt;li&gt;Text Here&lt;/li&gt;
    &lt;li&gt;Text Here&lt;/li&gt;
    &lt;li&gt;Text Here&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;  </pre>
<p>Let&#8217;s say you wanted to use JavaScript to change the background  color of the first list item element (<code>&lt;li&gt;</code>) in the unordered list above.  Using pure JavaScript, your code would look something like this:</p>
<pre>var myListCollection = document.getElementsByTagName(&quot;ul&quot;);
  for (var i = 0; i &lt; myListCollection.length; i++) {
    if (myListCollection[i].className === &quot;list&quot;) {
      myListCollection[i].childNodes[0].style.backgroundColor = &quot;blue&quot;;
    }
  }  </pre>
<p>Using jQuery, you can accomplish the same thing with just one, easy-to-maintain line of code:</p>
<pre>$(&quot;ul.list li:first-child&quot;).css(&quot;background-color, &quot;blue&quot;);  </pre>
<h4>Further reading</h4>
<ul>
<li><a href="http://javascript.about.com/od/hintsandtips/a/liborself.htm">JavaScript Library or Code Yourself</a></li>
<li><a href="http://simonwillison.net/static/2008/xtech/">Unobtrusive JavaScript with jQuery &#8211; Presentation</a></li>
</ul>
<h3>Understand CSS concepts</h3>
<p>One area that is imperative to powerful jQuery development, is  strong knowledge of CSS. The reason for this is because jQuery often  utilizes CSS-based syntax to manipulate DOM elements. Here are some  concepts that you should be quite familiar with before diving into  extensive jQuery development:</p>
<ul>
<li>Type selectors</li>
<li>Class selectors</li>
<li>ID selectors</li>
<li>Descendant Selectors</li>
<li>Child Selectors</li>
<li>Attribute Selectors</li>
<li>CSS Specificity</li>
<li>The Cascade &amp; Inheritance</li>
</ul>
<p>Most of the above CSS concepts should already be very familiar to  any modern-day front-end developer, since any CSS layout would utilize  these. jQuery not only incorporates the basic selectors (type, class,  and ID), but it also uses descendant and child selectors, which aren&#8217;t  supported by all currently-used browsers. But with jQuery, due to its  built-in browser normalization, all selectors are supported equally.</p>
<p>Understanding that jQuery incorporates CSS syntax when accessing  elements will greatly enhance your ability to quickly and easily create  powerful JavaScript applications with jQuery.</p>
<ul>
<li><a href="http://www.w3.org/TR/CSS2/selector.html">CSS Selectors at W3.org</a></li>
<li><a href="http://www.smashingmagazine.com/2009/08/17/taming-advanced-css-selectors/">Taming Advanced CSS Selectors</a></li>
</ul>
<h3>Understand JavaScript concepts</h3>
<p>In order to make full use of jQuery, it is a good idea to learn  certain JavaScript concepts. Sure, you can do a ton of stuff in jQuery  without knowing much about some of the concepts listed below, but  you&#8217;ll have a bigger advantage in your jQuery development if you take  the time to understand a few fundamentals, including:</p>
<ul>
<li>Object creation</li>
<li>Properties of objects</li>
<li>Object literals</li>
<li>Functions as methods</li>
<li>Anonymous functions</li>
<li>Closures</li>
</ul>
<p>Again, it is not necessary to fully understand any of the above  concepts in order to start working with jQuery, but your abilities with  jQuery&#8217;s API will increase greatly if you understand one or more of the  above concepts.</p>
<ul>
<li><a href="http://www.devarticles.com/c/a/JavaScript/ObjectOriented-JavaScript-An-Introduction-to-Core-Concepts/">Object-Oriented JavaScript: An Introduction to Core Concepts</a></li>
<li><a href="http://www.webreference.com/programming/javascript/object-oriented_javascript/">Object-Oriented Javascript</a> at Webreference.com</li>
</ul>
<h3>The jQuery source code</h3>
<p>Before getting started with any jQuery development, you&#8217;ll first have to <a href="http://docs.jquery.com/Downloading_jQuery">download the latest version</a> of the jQuery library and include it in your pages:</p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;  </pre>
<p>The above line of HTML should appear before any actual jQuery code, otherwise you&#8217;ll get errors.</p>
<p>Alternatively, instead of hosting the source code yourself, you could link directly to the most recent version on the <a href="http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery">Google Ajax Libraries API</a> which can save you some server resources. (read <a href="http://sixrevisions.com/web-applications/website-features-that-you-can-easily-offload/">more ways to offload website features</a>).</p>
<h3>jQuery syntax</h3>
<p>Now that you have an overview of the benefits of jQuery, along with  some understanding of concepts involved, let&#8217;s take a look at some  syntax to get us started with this powerful library.</p>
<h4>The jQuery wrapper</h4>
<p>The jQuery wrapper is the function that is at the core of all jQuery  commands. I used it earlier in one of the examples above. Here it is  again:</p>
<pre>$(&quot;li a&quot;);</pre>
<p>The <code>$</code> symbol is an alias for the jQuery function, so the above line of code could alternatively be written:</p>
<pre>jQuery(&quot;li a&quot;);</pre>
<p>But, for obvious reasons (e.g. to keep your code terse), you&#8217;ll rarely see that syntax.</p>
<p>The jQuery function shown in the above two examples  returns an object containing an array of the DOM elements specified  inside the parentheses (in this case, all anchor tags that are nested  inside of <code>&lt;li&gt;</code> tags). Of course, in both examples  above, we haven&#8217;t specified an action; all we&#8217;re doing is returning  those DOM elements, which does nothing. In the next section, we&#8217;ll add  methods that will act on the group of elements we&#8217;re targeting.</p>
<h4>jQuery commands</h4>
<p>jQuery&#8217;s API includes easy access to effects and other actions via  built-in methods that would normally take dozens of lines of code to  accomplish in a cross-browser fashion with pure JavaScript. For  example, let&#8217;s add a &quot;fade out&quot; method to the code from the previous  examples:</p>
<pre>$(&quot;li a&quot;)<strong>.fadeOut()</strong>;  </pre>
<p>The above line of code &quot;fades out&quot; all anchor tags on the page that are nested inside of <code>&lt;li&gt;</code> tags. If we want to fade the anchors back in again, we just use the <code>fadeIn()</code> method:</p>
<pre>$(&quot;li a&quot;)<strong>.fadeIn()</strong>;  </pre>
<h4>Chaining commands</h4>
<p>jQuery also allows developers to chain commands, stringing one after  another. So, we could combine the previous two examples, as follows:</p>
<pre>$(&quot;li a&quot;).fadeOut().fadeIn();  </pre>
<p>The above code will fade out all anchor tags nested within list  items, then immediately fade them back in. The number of chained items  is infinite (or within reasonably set limits), allowing for numerous  commands to work on the same group of elements, each happening in  succession.</p>
<p>That&#8217;s just a small sampling of what&#8217;s possible with jQuery, and how  easy it is to accomplish tasks that would normally take many lines of  code, and a lot of browser testing. Although you&#8217;ll still do browser  testing when running jQuery code, the results will virtually always be  the same: cross-browser, unobtrusive JavaScript that&#8217;s easy to write  and easy to maintain.</p>
<h4>Running code when the DOM is ready</h4>
<p>Earlier we touched on the concept of unobtrusive JavaScript, and how  jQuery is written to allow your scripts to remain separate from content  and presentation. So far, the code examples we&#8217;ve discussed would run  fine as long as they were included at the bottom of an HTML page. If,  on the other hand, they were included in the head of the document, they  would fail to work because, at that point, the document tree has not  yet rendered.</p>
<p>jQuery allows us to run our code only when the DOM is ready. This is done by means of the <code>$(document).ready</code>  handler. The beauty of this handler is that it doesn&#8217;t make the code  wait until the entire page finishes loading, as would be the case with  a typical <code>window.onload</code> event. With the (document).ready  handler, your code will run as soon as the DOM tree is finished  rendering, before all images and other media have finished loading,  thus minimizing load time.</p>
<p>Let&#8217;s try running our previous code example when the DOM is ready:</p>
<pre>$(document).ready(function(){
  $(&quot;li a&quot;).fadeOut().fadeIn();
});  </pre>
<p>The above code tells jQuery to run an anonymous function when the  document tree is done rendering. The anonymous function contains the  code we saw previously, which faded our anchors out, then immediately  faded them back in again. This code could be included in the <code>&lt;head&gt;</code> of the document, near the bottom of the page, or anywhere else, and it would run exactly the same way.</p>
<p>The &quot;ready&quot; event is just one of the many events available through jQuery&#8217;s API. Others include <code>click</code>, <code>dblclick</code>, <code>load</code>, <code>blur</code>, <code>keydown</code>, <code>submit</code>, and more.</p>
<h4>Further reading</h4>
<ul>
<li><a href="http://docs.jquery.com/Main_Page">jQuery Documentation</a></li>
<li><a href="http://docs.jquery.com/Events">Event-Related Functions in the jQuery API</a></li>
<li><a href="http://docs.jquery.com/Events/ready">The jQuery Ready Event</a></li>
</ul>
<h3>Conclusion</h3>
<p>jQuery is capable of so much more, and I&#8217;ve only just begun  demonstrating its power and simplicity. But I think this suffices to  provide a good overview, with some syntax basics, thus preparing  beginning jQuery developers for easy-to-write and practical JavaScript  code.</p>
<h3>Further reading</h3>
<ul>
<li><a href="http://docs.jquery.com/Tutorials">jQuery General Tutorials</a></li>
<li><a href="http://www.noupe.com/tutorial/51-best-of-jquery-tutorials-and-examples.html">51+ jQuery Tutorials</a></li>
<li><a href="http://webitect.net/coding/30-jquery-tutorials-for-complete-beginners/">30 jQuery Tutorials for Complete Beginners</a></li>
</ul>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/">Create a Slick and Accessible Slideshow Using jQuery</a></li>
<li><a href="http://sixrevisions.com/resources/14-jquery-plugins-for-working-with-images/">14 jQuery Plugins for Working with Images</a></li>
<li><a href="http://sixrevisions.com/javascript/40-exceptional-jquery-interface-techniques-and-tutorials/">40 Exceptional jQuery Interface Techniques and Tutorials</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and Web <a href="http://sixrevisions.com/category/web-development/">Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/louis_lazaris_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Louis Lazaris</strong> is a writer and freelance web developer based in  Toronto, Canada. He has 9 years of experience in the web development  industry and posts <a href="http://www.impressivewebs.com/articles/">web design articles</a> and <a href="http://www.impressivewebs.com/tutorials/">tutorials</a> on his blog, <a href="http://www.impressivewebs.com">Impressive Webs</a>. Follow Louis on <a href="http://twitter.com/ImpressiveWebs">Twitter</a> or contact him through <a href="http://www.impressivewebs.com/contact/">this form</a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/getting-started-with-jquery/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>10 Awesome Techniques and Examples of Animation with jQuery</title>
		<link>http://sixrevisions.com/javascript/10-awesome-techniques-and-examples-of-animation-with-jquery/</link>
		<comments>http://sixrevisions.com/javascript/10-awesome-techniques-and-examples-of-animation-with-jquery/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 02:51:24 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=1900</guid>
		<description><![CDATA[In this article, we share with you some innovative uses of jQuery in animating web design elements. You'll read about some interesting techniques, tutorials, and examples that will show you how to create similar effects on your own websites and web apps.]]></description>
			<content:encoded><![CDATA[<p><img src="http://images.sixrevisions.com/2009/11/01-01_animation_jquery_lead_image.jpg" width="550" height="250" alt="10 Awesome Techniques and Examples of Animation with jQuery" /></p>
<p>jQuery can pretty much do anything you can think of. All you need is a creative imagination and some time to learn the simple and intuitive <a href="http://api.jquery.com/">API</a>.</p>
<p>In this article, we share with you some innovative uses of jQuery in animating web design elements. You&#8217;ll read about some interesting techniques, tutorials, and examples that will show you how to create similar effects on your own websites and web apps.</p>
<p><span id="more-1900"></span></p>
<h3>1. <a href="http://www.gayadesign.com/diy/puffing-smoke-effect-in-jquery/" target="_blank">Puffing Smoke Effect in jQuery</a></h3>
<p><a href="http://www.gayadesign.com/diy/puffing-smoke-effect-in-jquery/"><img src="http://images.sixrevisions.com/2009/11/01-02_puffing_smoke.jpg" width="500" height="170" alt="Puffing Smoke Effect in jQuery" /></a></p>
<p>This example by Dutch web developer Gaya Kessler features an impressive animation effect of cartoonish smoke emanating from factory smoke stacks. Kessler thoughtfully supplies a configurable jQuery plugin with instructions based on his site&#8217;s header, so that you may create a similar animation effect for your website.</p>
<p><strong>Live Demo: <a href="http://www.gayadesign.com/scripts/smokeeffect/">Smoke Effect</a></strong></p>
<h3>2. <a href="http://buildinternet.com/2009/08/crafting-an-animated-postcard-with-jquery/" target="_blank">Crafting an Animated Postcard</a></h3>
<p><a href="http://buildinternet.com/2009/08/crafting-an-animated-postcard-with-jquery/"><img src="http://images.sixrevisions.com/2009/11/01-03_postcard.jpg" width="500" height="219" alt="Crafting an Animated Postcard" /></a></p>
<p>Sam Dunn of the web development duo, Build Internet, wrote a tutorial on how to create an animated landscape using transparent PNG images. The tutorial takes advantage of the popular <a href="http://gsgd.co.uk/sandbox/jquery/easing/">jQuery Easing plugin</a> to help with the animation and the <code>setTimeout()</code> JavaScript function to time the events accordingly.</p>
<p><strong>Live Demo: <a href="http://buildinternet.com/live/postcard/">Animated Postcard</a></strong></p>
<h3>3. <a href="http://www.adrianpelletier.com/2009/05/31/create-a-realistic-hover-effect-with-jquery-ui/" target="_blank">Create a Realistic Hover Effect</a></h3>
<p><a href="http://www.adrianpelletier.com/2009/05/31/create-a-realistic-hover-effect-with-jquery-ui/"><img src="http://images.sixrevisions.com/2009/11/01-04_jquery_hover.jpg" width="500" height="299" alt="Create a Realistic Hover Effect" /></a></p>
<p>In this tutorial, you will learn how to animate image elements in a smooth and fluid manner. The tutorial features objects that, when hovered on, rises upwards. In the live demo of the effect, notice how the reflections and shadows at the bottom also changes when the object lifts up; hence &quot;realistic&quot; in the name of the technique.</p>
<p><strong>Live Demo: <a href="http://adrianpelletier.com/sandbox/jquery_hover_nav/">Realistic Hover Effect</a></strong></p>
<h3>4. <a href="http://youlove.us/blog/the-youloveus-scrolling-background-effect-explained" target="_blank">Scrolling Background Effect</a></h3>
<p><a href="http://youlove.us/blog/the-youloveus-scrolling-background-effect-explained"><img src="http://images.sixrevisions.com/2009/11/01-06_scrolling_background.jpg" width="500" height="117" alt="Scrolling Background Effect" /></a></p>
<p>The creators of the site youlove.us shares their code (and explanation) for making a seamless vertical scrolling CSS background; featured on the site&#8217;s header. The script is also dependent on the user&#8217;s system time; the animation starts at a different position depending on whether you visit the site at night or in the morning, a nice touch.</p>
<p><strong>Live Demo: <a href="http://youlove.us/">youlove.us</a> (web page header)</strong></p>
<h3>5. <a href="http://visitmix.com/lab/glimmer" target="_blank">Multiple Animations with Glimmer</a></h3>
<p><a href="http://visitmix.com/lab/glimmer"><img src="http://images.sixrevisions.com/2009/11/01-05_glimmer.jpg" width="500" height="199" alt="Multiple Animations with Glimmer" /></a></p>
<p>Glimmer, a JavaScript animation creation tool that leverages the jQuery library, has several live demonstrations for some of the things you can do with the app. For instance, with Glimmer, you can create cool <a href="http://visitmix.com/labs/glimmer/samples/freestyle.html">animation sequences</a> or make a spiffy and impressive <a href="http://visitmix.com/labs/glimmer/samples/sequence.html">rotating banner</a> for your website.</p>
<p><strong>Live Demos: <a href="http://visitmix.com/labs/glimmer/samples/freestyle.html">Freestyle Sample</a>, <a href="http://visitmix.com/labs/glimmer/samples/sequence.html">Image Sequence Sample</a>, <a href="http://visitmix.com/labs/glimmer/samples/paraFade.html">Fade Text Sample</a></strong></p>
<h3>6. <a href="http://colorpowered.com/blend/" target="_blank">jQuery Blend</a></h3>
<p><a href="http://colorpowered.com/blend/"><img src="http://images.sixrevisions.com/2009/11/01-07_jquery_blend.jpg" width="500" height="329" alt="jQuery Blend" /></a></p>
<p>jQuery Blend is a plugin for animating CSS background images. The project emphasizes on web development best practices such as <a href="http://en.wikipedia.org/wiki/Progressive_enhancement">progressive enhancement</a>  so that users with JavaScript disabled are still able to interact with your interface, albeit without the animation effects, making for a truly universal design.</p>
<p><strong>Live Demo: <a href="http://colorpowered.com/blend/">website navigation with different options</a></strong></p>
<h3>7. <a href="http://blog.themeforest.net/tutorials/create-a-funky-parallax-background-effect-using-jquery/" target="_blank">Parallax Scrolling Background</a></h3>
<p><a href="http://blog.themeforest.net/tutorials/create-a-funky-parallax-background-effect-using-jquery/"><img src="http://images.sixrevisions.com/2009/11/01-08_scrolling_background.jpg" width="500" height="227" alt="Parallax Scrolling Background" /></a></p>
<p>In this jQuery tutorial, you will learn how to construct a <a href="http://en.wikipedia.org/wiki/Parallax_scrolling">Parallax Scrolling</a> background &#8211; first popularized in web interfaces with the use of Flash. The technique involves div elements with CSS background images. The Parallax Scrolling technique requires the <a href="http://flesler.blogspot.com/2007/10/jqueryscrollto.html">scrollTo plugin</a> by Argentinean Web Developer and Game Programmer, Ariel Flesler.</p>
<p><strong>Live Demo: <a href="http://themeforest.s3.amazonaws.com/116_parallax/tutorial-source-files/tut-index.html">Scrolling Clouds</a></strong></p>
<h3>8. <a href="http://www.queness.com/post/620/create-a-stunning-sliding-door-effect-with-jquery" target="_blank">Stunning Sliding Door Effect</a></h3>
<p><a href="http://www.queness.com/post/620/create-a-stunning-sliding-door-effect-with-jquery"><img src="http://images.sixrevisions.com/2009/11/01-09_jquery_sliding.jpg" width="500" height="293" alt="Stunning Sliding Door Effect" /></a></p>
<p>Designer and Developer Kevin Liew shows other website builders how to create a striking animation effect where a top image splits up into four pieces, moving smoothly to the corners, and revealing another image beneath it. It&#8217;s an animation effect suited for interactive thumbnails of images.</p>
<p><strong>Live Demo: <a href="http://www.queness.com/resources/html/slicing/index.html">Sliding Door Effect</a></strong></p>
<h3>9. <a href="http://design-notes.info/tutorial/jquery-tutorial/make-your-header-responses-to-mouse-movements-with-jparallax/" target="_blank">Make Your Header Responses to Mouse Movements</a></h3>
<p><a href="http://design-notes.info/tutorial/jquery-tutorial/make-your-header-responses-to-mouse-movements-with-jparallax/"><img src="http://images.sixrevisions.com/2009/11/01-10_jquery_mouse_movement.jpg" width="500" height="350" alt="Make Your Header Responses to Mouse Movements" /></a></p>
<p>In this jQuery animation technique, you will learn how to animate a set of images that reacts to the user&#8217;s mouse movements. When the user hovers over a set of images, the set begins to follow the mouse cursor. This technique can be adapted to many user interface related functions, or you can just use it to impart a memorable experience to your users.</p>
<p><strong>Live Demo: <a href="http://design-notes.info/demo/parallax.html">parallax</a></strong></p>
<h3>10. <a href="http://www.devirtuoso.com/2009/07/how-to-build-an-animated-header-in-jquery/" target="_blank">Animated Header Using jQuery</a></h3>
<p><a href="http://www.devirtuoso.com/2009/07/how-to-build-an-animated-header-in-jquery/"><img src="http://images.sixrevisions.com/2009/11/01-11_animated_header.jpg" width="500" height="188" alt="Animated Header Using jQuery" /></a></p>
<p>This animated tutorial goes over a similar concept to the youlove.us example of vertically moving a large CSS background image. Illustrations on how the technique works will help readers grok the concept more fully. Devirtuoso, the author of the tutorial, goes through due diligence by offering an IE6 hack for backwards compatibility.</p>
<p><strong>Live Demo: <a href="http://www.devirtuoso.com/Examples/jQuery-Animated-Header/">Animated Header</a></strong></p>
<p><strong>Can jQuery replace Flash?</strong> Do you know of other impressive uses of jQuery to animate page elements? Why don&#8217;t we talk about it in the comments? <em>*Co-written by Jacob Gube</em></p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/javascript/20-fresh-jquery-plugins-to-enhance-your-user-interface/">20 Fresh jQuery Plugins to Enhance your User Interface</a></li>
<li><a href="http://sixrevisions.com/resources/14-jquery-plugins-for-working-with-images/">14 jQuery Plugins for Working with Images</a></li>
<li><a href="http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/">Create a Slick and Accessible Slideshow Using jQuery</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/kawsar_ali_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Kawsar Ali</strong> is a web designer, graphic designer, and wannabe photographer  based in NY, U.S. He&#8217;s also the founder of <a href="http://desizntech.info/"><strong>Desizntech</strong></a>, a site to find  tips about web design, Mac, PC and more. If you&#8217;d like to connect with  him, you can follow him on <a href="https://twitter.com/desizntech" target="_blank"><strong>Twitter</strong></a> or at his<a href="http://i-exist.co.cc/" target="_blank"><strong> Personal Website</strong></a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/10-awesome-techniques-and-examples-of-animation-with-jquery/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>6 Advanced JavaScript Techniques You Should Know</title>
		<link>http://sixrevisions.com/javascript/6-advanced-javascript-techniques-you-should-know/</link>
		<comments>http://sixrevisions.com/javascript/6-advanced-javascript-techniques-you-should-know/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 16:00:09 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=1771</guid>
		<description><![CDATA[Here are some advanced JavaScript techniques and tips all web developers should know.]]></description>
			<content:encoded><![CDATA[<p><img src="http://images.sixrevisions.com/2009/10/08-01_advanced_js_techniques_lead.jpg" width="550" height="200" alt="6 Advanced JavaScript Techniques You Should Know" /></p>
<p>There have been a number of articles published over the years that  discuss best practices techniques for JavaScript. I thought I would go  a little bit beyond the scope of those articles and outline a number of  advanced techniques and practices that I have personally used or read  about that could be invaluable in certain circumstances.</p>
<p><span id="more-1771"></span></p>
<p>This article doesn&#8217;t necessarily cover every detail of the methods  I&#8217;m describing, but provides an overview, along with code examples, of  some practical JavaScript coding techniques.</p>
<h3>1. Closures to Extend Variable Scope</h3>
<p>Closures in JavaScript are a fairly straightforward concept, and  have been discussed online in a number of in-depth articles. The fact  that they are straightforward doesn&#8217;t necessarily mean they&#8217;re simple  however, as seen by the extensive articles that cover the subject.</p>
<p>Simply put, closures allow variable scope to be extended past the  common scope restrictions of functions. I like the way Jeremy Keith  describes closures in his book <em><a href="http://bulletproofajax.com/">Bulletproof Ajax</a></em>:</p>
<blockquote><p>&quot;Think of closures as a kind of regional scope: broader than local but not as broad as global.&quot;</p></blockquote>
<p>To create a closure, you nest a function inside of a function. That  inner function has access to all variables in its parent function&#8217;s  scope. This comes in handy when creating methods and properties in  object oriented scripts. Here is a simple example that demonstrates the  use of a closure:</p>
<pre>
function myObject() {
  this.property1 = &quot;value1&quot;;
  this.property2 = &quot;value2&quot;;
  var newValue = this.property1;
<strong>  this.performMethod = function() {
    myMethodValue = newValue;
    return myMethodValue;
  };</strong>
  }
  var myObjectInstance = new myObject();
  <strong>alert(myObjectInstance.performMethod());</strong>
</pre>
<p>The key portions of the script are the nested anonymous function  are highlighted in green and the method call in the <code>alert</code> function (last line). Because the  method in the alert is actually calling a nested function, that method  is able to read the value of the variable called <code>newValue</code>, even thought that variable is not within the scope of the anonymous function, or method.</p>
<p>Developers use closures all the time, probably unknowingly, since a  closure is created any time an anonymous function is nested inside  another function and utilizes variables from the parent function&#8217;s  scope. The power of the closure is revealed when that method (the inner  function) is called, and values that normally wouldn&#8217;t be accessible  are within &quot;regional&quot; scope and are thus able to be used as any other  value.</p>
<p>See the references below for some deeper explanations of closures  and their relation to scope. I also highly recommend you pick up a good  advanced JavaScript book that offers a good discussion of the concepts  associated with closures.</p>
<h4>Further Reading</h4>
<ul>
<li><a href="http://robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/">Explaining JavaScript scope and closures (Robert Nyman)</a></li>
<li><a href="http://james.padolsey.com/javascript/closures-in-javascript/">Closures in JavaScript (James Padolsey)</a></li>
<li><a href="http://www.jibbering.com/faq/faq_notes/closures.html">JavasCript Closures at Jibbering.com</a></li>
<li><a href="http://blog.morrisjohns.com/javascript_closures_for_dummies">JavaScript Closures for Dummies</a></li>
</ul>
<h3>2. Object Literals to Pass Optional Arguments</h3>
<p>Here is a handy coding tip to keep in mind when dealing with  functions that can accept a large number of optional arguments. Instead  of passing the large number of arguments in the conventional fashion,  which could unnecessarily complicate the function, you can pass just  one argument which ends up being a collection of arguments declared in  an object literal.</p>
<p>Let&#8217;s look, first of all, at how we might do this in the typical manner, so we can see the contrast:</p>
<pre>function showStatistics(name, team, position, average, homeruns, rbi) {
  document.write(&quot;&lt;p&gt;&lt;strong&gt;Name:&lt;/strong&gt; &quot; + arguments[0] + &quot;&lt;br /&gt;&quot;);
  document.write(&quot;&lt;strong&gt;Team:&lt;/strong&gt; &quot; + arguments[1] + &quot;&lt;br /&gt;&quot;);

  if (typeof arguments[2] === &quot;string&quot;) {
    document.write(&quot;&lt;strong&gt;Position:&lt;/strong&gt; &quot; + position + &quot;&lt;br /&gt;&quot;);
  }
  if (typeof arguments[3] === &quot;number&quot;) {
    document.write(&quot;&lt;strong&gt;Batting Average:&lt;/strong&gt; &quot; + average + &quot;&lt;br /&gt;&quot;);
  }
  if (typeof arguments[4] === &quot;number&quot;) {
    document.write(&quot;&lt;strong&gt;Home Runs:&lt;/strong&gt; &quot; + homeruns + &quot;&lt;br /&gt;&quot;);
  }
  if (typeof arguments[5] === &quot;number&quot;) {
    document.write(&quot;&lt;strong&gt;Runs Batted In:&lt;/strong&gt; &quot; + rbi + &quot;&lt;/p&gt;&quot;);
  }
}
showStatistics(&quot;Mark Teixeira&quot;);
showStatistics(&quot;Mark Teixeira&quot;, &quot;New York Yankees&quot;);
showStatistics(&quot;Mark Teixeira&quot;, &quot;New York Yankees&quot;, &quot;1st Base&quot;, .284, 32, 101);  </pre>
<p>The function above can take up to 6 arguments. The first two  arguments are mandatory, so inside the function, we don&#8217;t check for  their existence. The last 4 arguments are not mandatory, so we only  display their values if they exist.</p>
<p>We call the function 3 different times (last 3 lines), with  different numbers of arguments each time. You can see that if the  number of passed arguments was in the dozens, or more, the code could  look a little messy, and would be harder to maintain, or read.</p>
<p>Now let&#8217;s look at the same code using object literals to pass the arguments:</p>
<pre>function <strong>showStatistics(args)</strong> {
  document.write(&quot;&lt;p&gt;&lt;strong&gt;Name:&lt;/strong&gt; &quot; + args.name + &quot;&lt;br /&gt;&quot;);
  document.write(&quot;&lt;strong&gt;Team:&lt;/strong&gt; &quot; + args.team + &quot;&lt;br /&gt;&quot;);
  if (typeof args.position === &quot;string&quot;) {
    document.write(&quot;&lt;strong&gt;Position:&lt;/strong&gt; &quot; + args.position + &quot;&lt;br /&gt;&quot;);
  }
  if (typeof args.average === &quot;number&quot;) {
    document.write(&quot;&lt;strong&gt;Average:&lt;/strong&gt; &quot; + args.average + &quot;&lt;br /&gt;&quot;);
  }
  if (typeof args.homeruns === &quot;number&quot;) {
    document.write(&quot;&lt;strong&gt;Home Runs:&lt;/strong&gt; &quot; + args.homeruns + &quot;&lt;br /&gt;&quot;);
  }
  if (typeof args.rbi === &quot;number&quot;) {
    document.write(&quot;&lt;strong&gt;Runs Batted In:&lt;/strong&gt; &quot; + args.rbi + &quot;&lt;/p&gt;&quot;);
  }
}

<strong>showStatistics</strong>({
  name: &quot;Mark Teixeira&quot;
});

<strong>showStatistics</strong>({
  name: &quot;Mark Teixeira&quot;,
  team: &quot;New York Yankees&quot;
});

<strong>showStatistics</strong>({
  name: &quot;Mark Teixeira&quot;,
  team: &quot;New York Yankees&quot;,
  position: &quot;1st Base&quot;,
  average: .284,
  homeruns: 32,
  rbi: 101
});  </pre>
<p>Technically, this second method of passing the arguments might  require a little bit more code, but with a large collection of  arguments, there are a few advantages.</p>
<p>First, the function itself is  simplified because it accepts only one argument (<code>args</code>),  which is a collection of all the values passed from the object literal (<code>name</code>, <code>team</code>, <code>position</code>, etc). Plus, the actual argument values are easy  to read, and can easily be understood, updated, or modified, since the  correlation between the values and the argument references are more  direct.</p>
<p>If the function required only a small number of arguments, then this  method would not be necessary, and might actually have the opposite  effect. So, use this technique sparingly, and only in situations where  you foresee the collection of arguments being hard to maintain over  time.</p>
<h4>Further Reading</h4>
<ul>
<li><a href="http://www.dyn-web.com/tutorials/obj_lit.php">JavaScript Object Literal</a></li>
<li><a href="http://www.evotech.net/blog/2008/07/javascript-object-literals-a-definition/">JavaScript Object Literals Simplified</a></li>
<li><a href="http://www.javascriptkit.com/javatutors/oopjs.shtml">JavaScript and Object Oriented Programming (OOP)</a></li>
</ul>
<h3>3. Contextual Targeting of DOM Elements</h3>
<p>There are sometimes instances where you need to traverse the DOM and  gain access to a specific element, or group of elements, but due to  certain restrictions, you may not have direct access to the elements  via a CSS class name or ID in the HTML code. This might be because of  user-generated content produced through a rich text editor, or dynamic  content pulled from a database.</p>
<p>Whatever the case, it&#8217;s not impossible to access those unidentified  DOM elements via JavaScript. Using what I call &quot;contextual targeting&quot;,  you can gain access to, and modify, almost any element in the DOM. As  long as you have a map of the general template that contains the  element you want to target, you can access that element and manipulate  it the same way you would an element that has a class name or ID.</p>
<p>Let&#8217;s create some basic HTML code that will serve as our example page:</p>
<pre>&lt;div id=&quot;header&quot;&gt;
  &lt;h1&gt;Site Title&lt;/h1&gt;
&lt;/div&gt;
&lt;div id=&quot;sidebar&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Testing&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Testing&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Testing&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Testing&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Testing&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Testing&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&quot;content&quot;&gt;
  &lt;h2&gt;Page Title&lt;/h2&gt;
  &lt;p&gt;&lt;a href=&quot;#&quot;&gt;Lorum Ipsum link here&lt;/a&gt;. Pellentesque habitant morbi
     tristique senectus et netus et malesuada fames ac turpis egestas.
     Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet,
     ante. Donec eu libero sit amet quam egestas semper.
     Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
     Pellentesque habitant morbi tristique senectus et netus et malesuada
     fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae,
     ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam
     egestas semper. Aenean ultricies mi vitae est. Mauris
     placerat eleifend leo.&lt;/p&gt;
  &lt;p&gt;&lt;span style=&quot;color: red;&quot;&gt;Pellentesque habitant morbi&lt;/span&gt;
    tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum
    tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec
    eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
    Mauris placerat eleifend leo. Pellentesque habitant morbi tristique senectus
    et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam,
    feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit
    amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat
    eleifend leo.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&quot;footer&quot;&gt;
   &lt;p&gt;Copyright | &lt;a href=&quot;#&quot;&gt;contact&lt;/a&gt; | &lt;a href=&quot;#&quot;&gt;policy&lt;/a&gt; |
      &lt;a href=&quot;#&quot;&gt;privacy&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;  </pre>
<p>Using the HTML code above, if we wanted to target all the anchor  tags on the page, we could collect them and manipulate them like this:</p>
<pre>var myLinkCollection = document.<strong>getElementsByTagName(&quot;a&quot;)</strong>;

for (i=0;i&lt;myLinkCollection.length;i++) {
  // do something with the anchor tags here
}  </pre>
<p>If we wanted to target only the anchor tags in the footer, however,  we would target them based on their context, or surrounding elements,  like this:</p>
<pre>var myFooterElement = document<strong>.getElementById(&quot;footer&quot;)</strong>;
var myLinksInFooter = myFooterElement<strong>.getElementsByTagName(&quot;a&quot;)</strong>;
for (i=0;i&lt;myLinksInFooter.length;i++) {
  // do something with footer anchor tags here
}  </pre>
<p>The first line grabs a reference to the footer element. The second line collects all <code>&lt;a&gt;</code>  tags inside the footer. Then we loop through them and do what we want  with them. Thus, they are accessible even though they are not grouped  via class names.</p>
<p>You can accomplish the same thing by using node properties, as shown below.</p>
<pre>var myLinkCollection = document.<strong>getElementsByTagName</strong>(&quot;a&quot;);

for (i=0;i&lt;myLinkCollection.length;i++) {
  if (<strong>myLinkCollection[i].parentNode.parentNode.id</strong> === &quot;footer&quot;) {
    // do something with footer anchor tags here
  }
}  </pre>
<p>Similar code could be used to target the lone anchor tag inside the &quot;content&quot; section.</p>
<p>We could also limit our anchor tag search to include only tags that have the <code>href</code> attribute set, so as to avoid finding any in-page links. We do this by using the <code>getAttribute</code> method:</p>
<pre>var myLinkCollection = document.getElementsByTagName(&quot;a&quot;);

for (i=0;i&lt;myLinkCollection.length;i++) {
  if (myLinkCollection[i].<strong>getAttribute(&quot;href&quot;)</strong>) {
    // do something with the anchor tags here
  }
}  </pre>
<p>Finally, you&#8217;ll notice that there is a <code>&lt;span&gt;</code> tag  with an inline style. The inline style could have been generated  through a content management system, so you may not have the ability to  edit it directly. You can target all <code>&lt;span&gt;</code> elements with inline styles like this:</p>
<pre>var myLinkCollection = document.<strong>getElementsByTagName(&quot;span&quot;)</strong>;

for (i=0;i&lt;myLinkCollection.length;i++) {
  if (myLinkCollection[i].getAttribute(&quot;style&quot;)) {
    // do something with all anchors that have inline styles
  }
}  </pre>
<p>The possibilities are endless with contextual targeting, and there  are even more options available if you&#8217;re using a JavaScript library  that normalizes browser differences and simplifies DOM manipulation.</p>
<h4>Further Reading:</h4>
<ul>
<li><a href="http://reference.sitepoint.com/javascript/Document/getElementsByTagName">getElementsByTagName at Sitepoint&#8217;s JavaScript Reference</a></li>
<li><a href="http://www.w3schools.com/HTMLDOM/met_doc_getelementsbytagname.asp">getElementsByTagName at W3Schools</a></li>
</ul>
<h3>4. Using Namespaces to Prevent Conflicts</h3>
<p>If you&#8217;re doing an extensive amount of raw JavaScript coding and  suspect that additions could be made to the same pages you&#8217;re working  on, you can prevent any future conflicts with your code by giving your  code its own namespace.</p>
<p>Object-oriented JavaScript implements namespace-like principles due  to the fact that properties and methods are declared inside of objects,  thus there are less likely to be conflicts. A conflict could arise,  however, through object names. And very likely, the conflict will occur  &quot;silently&quot;, thus you may not be alerted to the issue immediately.</p>
<p>You can prevent all conflicts by creating a unique namespace. Let&#8217;s use the <code>showStatistics</code> function to demonstrate how we can encapsulate code into its own namespace:</p>
<pre>if (typeof MY == &quot;undefined&quot;) {
  MY = new Object();
  MY.CUSTOM = new Object();
}

MY.CUSTOM.namespace = function() {
  function showStatistics(args) {
    document.write(&quot;&lt;p&gt;&lt;strong&gt;Name:&lt;/strong&gt; &quot; + args.name + &quot;&lt;br /&gt;&quot;);
    document.write(&quot;&lt;strong&gt;Team:&lt;/strong&gt; &quot; + args.team + &quot;&lt;br /&gt;&quot;);
    if (typeof args.position === &quot;string&quot;) {
      document.write(&quot;&lt;strong&gt;Position:&lt;/strong&gt; &quot; + args.position + &quot;&lt;br /&gt;&quot;);
    }
    if (typeof args.average === &quot;number&quot;) {
      document.write(&quot;&lt;strong&gt;Average:&lt;/strong&gt; &quot; + args.average + &quot;&lt;br /&gt;&quot;);
    }
    if (typeof args.homeruns === &quot;number&quot;) {
      document.write(&quot;&lt;strong&gt;Home Runs:&lt;/strong&gt; &quot; + args.homeruns + &quot;&lt;br /&gt;&quot;);
    }
    if (typeof args.rbi === &quot;number&quot;) {
      document.write(&quot;&lt;strong&gt;Runs Batted In:&lt;/strong&gt; &quot; + args.rbi + &quot;&lt;/p&gt;&quot;);
    }
  }

  showStatistics({
    name: &quot;Mark Teixeira&quot;,
    team: &quot;New York Yankees&quot;,
    position: &quot;1st Base&quot;,
    average: .284,
    homeruns: 32,
    rbi: 101
  });
}
MY.CUSTOM.namespace();  </pre>
<p>The first few lines create the namespace by checking to see if the  &quot;<code>MY</code>&quot; object already exists. This object can be whatever you want it to  be. Just pick a name that you don&#8217;t think will ever be used again.  After the <code>MY</code> object is created, we are then able to create the &quot;<code>CUSTOM</code>&quot;  object as a property of the <code>MY</code> object. Then our <code>namespace</code> function  becomes a method of the <code>MY.CUSTOM</code> object. Keep in mind that &quot;<code>MY</code>&quot;,  &quot;<code>CUSTOM</code>&quot; and &quot;<code>namespace</code>&quot; can each be your own custom names. I chose  these for demonstration purposes. They could be <code>CHEESEBURGER.ONIONS.pickles</code> if you want!</p>
<p>The <code>showStatistics</code> function is exactly the same as in  the example earlier that utilizes an object literal to pass in the  values. But in this case, the entire function, including the object  literal, is encapsulated inside <code>my.custom.namespace</code>. The  last line invokes the entire function using dot notation, and the  function runs exactly the same as it normally would, except that it is  protected from conflicting with another function called  &quot;<code>showStatistics</code>&quot;.</p>
<h4>Further Reading:</h4>
<ul>
<li><a href="http://javascript.about.com/od/objectorientedjavascript/a/oop14.htm">Object Oriented JavaScript: Namespaces (About.com)</a></li>
<li><a href="http://www.dustindiaz.com/namespace-your-javascript/">Namespacing your JavaScript (Dustin Diaz)</a></li>
</ul>
<h3>5. Hybrid Application Development</h3>
<p>You can create powerful JavaScript applications if you use a  combination of a JavaScript library and raw JavaScript code. Many  JavaScript libraries are used to implement &quot;pretty&quot; animations and  other customizable effects&#8211;sometimes via plugins&#8211; that often don&#8217;t  require much to be added to them other than some custom values.</p>
<p>On the other hand, there may be situations where you&#8217;ll want to  accomplish something specificly requested by a client. Maybe it&#8217;s  something not available in a library and that requires extensive  coding, possibly utilizing Ajax and a variety of DOM methods.</p>
<p>There is no point in reinventing the wheel. You can implement your  favorite JavaScript library and take advantage of its simplified Ajax  calls, DOM methods, and normalization of browser differences. Thus, you  can have the advantages of the library, while still creating custom  scripts that are specific to your project.</p>
<h4>Further Reading:</h4>
<ul>
<li><a href="http://en.wikipedia.org/wiki/List_of_JavaScript_libraries">List of JavaScript libraries at Wikipedia</a></li>
<li><a href="http://www.smashingmagazine.com/2009/03/02/40-stand-alone-javascript-libraries-for-specific-purposes/">40 Useful JavaScript Libraries (Smashing Magazine)</a></li>
<li><a href="http://javascriptlibraries.com/">JavaScript Libraries: A directory of tools shaping the new web</a></li>
</ul>
<h3>6. Rendering Readable HTML</h3>
<p>Finally, this is a technique to use in situations that require  dozens of lines of HTML code being generated dynamically via  JavaScript. Take the following example:</p>
<pre>var pageContainer = document.getElementById(&quot;container&quot;);
var pageTitle = &quot;Content Title&quot;;
var authorBio = &quot;Mr. Lorum Ipsum&quot;;
var pageContent = &quot;Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here.&quot;;
var footerContent = &quot;Copyright 2009&quot;;
var HTMLCode = '\n&lt;h1&gt;' + pageTitle + '&lt;/h1&gt;\n
               &lt;div id=&quot;content&quot;&gt;\n
               &lt;p&gt;' + pageContent + '&lt;/p&gt;\n
               &lt;div id=&quot;author_bio&quot;&gt;\n
               &lt;p&gt;' + authorBio +'&lt;/p&gt;\n
               &lt;/div&gt;\n
               &lt;/div&gt;\n
               &lt;div id=&quot;footer&quot;&gt;
               &lt;p&gt;' + footerContent + '&lt;/p&gt;\n
               &lt;/div&gt;\n';

pageContainer.innerHTML = HTMLCode;  </pre>
<p>The line to take note of above is the one that declares the value of the HTMLCode  variable. It renders just find in the generated source code, since it  utilizes the &quot;new line&quot; character, so it looks like perfectly good  HTML. But if this line of code were any longer it would be extremely  difficult to read and maintain in the .js file.</p>
<p>Here is the same code as above, but implementing a much more organized method of displaying the HTML:</p>
<pre>

var pageContainer = document.getElementById(&quot;container&quot;);
var pageTitle = &quot;Content Title&quot;;
var authorBio = &quot;Mr. Lorum Ipsum&quot;;
var pageContent = &quot;Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here. Lorum ipsum line text here.
                   Lorum ipsum line text here.&quot;;
var HTMLCode = 	'\n' +
                '&lt;h1&gt;' + pageTitle + '&lt;/h1&gt;\n'
                '&lt;div id=&quot;content&quot;&gt;\n' +
                  '&lt;p&gt;' + pageContent + '&lt;/p&gt;\n' +
                  '&lt;div id=&quot;author_bio&quot;&gt;\n' +
                    '&lt;p&gt;' + authorBio + '&lt;/p&gt;\n' +
                  '&lt;/div&gt;\n'		        '&lt;/div&gt;\n' +
                '&lt;div id=&quot;footer&quot;&gt;' +
                  '&lt;p&gt;' + footerContent + '&lt;/p&gt;\n' +
                '&lt;/div&gt;\n';

pageContainer.innerHTML = HTMLCode;</pre>
<p>Now the code is much more readable, and conforms to the manner in  which HTML is rendered in an actual HTML page. It even includes proper  HTML indenting, and still uses the new line character to properly  format the outputted HTML.</p>
<h3>Conclusion</h3>
<p>Although I didn&#8217;t provide a detailed explanation of every concept  dealt with in this collection, I hope this list provided beginning and  intermediate JavaScript coders with an overview of a few fairly  advanced practical techniques that they can implement in future  projects or experiments.</p>
<p>Please feel free to comment on any of the techniques I&#8217;ve mentioned  and some specific ways that you have used them in your own applications.</p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/">JavaScript Debugging Techniques in IE 6</a></li>
<li><a href="http://sixrevisions.com/javascript/promising_javascript_frameworks/">10 Promising JavaScript Frameworks</a></li>
<li><a href="http://sixrevisions.com/resources/40_resources_for_javascript_coders/">40 Excellent Resources for JavaScript Coders</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/louis_lazaris_small.jpg" alt="" width="80" height="80" /><strong>Louis Lazaris</strong> is a freelance web developer based in Toronto,  Canada. He has 9 years of experience in the web development industry  and posts <a href="http://www.impressivewebs.com/articles/">web design articles</a> and <a href="http://www.impressivewebs.com/tutorials/">tutorials</a> on his blog, <a href="http://www.impressivewebs.com"><strong>Impressive Webs</strong></a>. Follow Louis on <a href="http://twitter.com/ImpressiveWebs"><strong>Twitter</strong></a> or contact him through <a href="http://www.impressivewebs.com/contact/"><strong>this form</strong></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/6-advanced-javascript-techniques-you-should-know/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>10 Easy jQuery Tricks for Designers</title>
		<link>http://sixrevisions.com/javascript/10-easy-jquery-tricks-for-designers/</link>
		<comments>http://sixrevisions.com/javascript/10-easy-jquery-tricks-for-designers/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 22:00:55 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=1435</guid>
		<description><![CDATA[Take a look at ten simple, effective, and useful tricks and techniques from several excellent jQuery developers and sites around the web that leverage the library to take your designs to another level.]]></description>
			<content:encoded><![CDATA[<p>There are plenty of jQuery tricks and techniques out there,  and the vast and powerful <a href="http://jquery.com/">jQuery</a> library can  meet almost anyone&#8217;s JavaScript&#8217;ing needs. Since jQuery makes JavaScript  accessible to designers who want to add simple interaction and visual  techniques into their design without knowing extensive programming knowledge,  it&#8217;s worth a few moments to explore this excellent library.</p>
<p>As any designer knows, adding small bits of extra visual detail  and user-friendliness can add professionalism and appeal to any web design. In  addition, for designers that sell templates, WordPress themes, and other types  of web designs, the use of jQuery in a design can be a great selling point.</p>
<p>Let&#8217;s take a look at <strong>ten  simple, effective, and useful tricks and techniques</strong> from several excellent  jQuery developers and sites around the web that leverage the library to take your  designs to another level.</p>
<h3>1. Equal-Height Columns</h3>
<p><img src="http://images.sixrevisions.com/2009/08/13-01_unequalcolumns.jpg" width="550" height="300" alt="Equal-Height Columns" /></p>
<p><span id="more-1435"></span></p>
<p>Columns with equal heights have always been a problem for  designers using <code>div</code>s, although now, there are quite a few solutions.  Among the solutions available to you is using jQuery. This technique only  requires a very small JavaScript function to handle everything, then some basic  integration with the main layout to make the magic happen.</p>
<p>The function and snippets for this approach is from <a href="http://www.cssnewbie.com/equal-height-columns-with-jquery/">CSSNewbie</a>.  If anyone would like more insight to how the function works, it&#8217;s all there.</p>
<p>To solve this problem with jQuery, just add this function to  your pages you wish to have equal heights (or include it as a JavaScript file &#8211;  which is better for maintainability).</p>
<pre>function equalHeight(group) {
  tallest = 0;
  group.each(function() {
    thisHeight = $(this).height();
    if(thisHeight &gt; tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}</pre>
<p>To get equal-height columns, link to the script that contains  the function, and put the following code block below in the <code>&lt;head&gt;</code>  tags of your pages.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
  equalHeight($(&quot;.col1&quot;));
  equalHeight($(&quot;.col2&quot;));
  equalHeight($(&quot;.col3&quot;));
});
&lt;/script&gt;</pre>
<p>The code will execute as soon as the DOM is ready to be  utilized, (<code>$(document).ready(function()</code>) and then uses the <code>equalHeight</code>  function to accurately calculate the height of all the columns. As one can see,  all a designer needs to do is use <code>div</code>s with classes of <code>col1</code>, <code>col2</code>,  and <code>col3</code> to make this example work properly.</p>
<h3>2. Rounded corners without the HTML mess</h3>
<p>Fortunately, CSS3 has come out with a way to create rounded  corners automatically without using images, but on the other hand, many popular  browsers (such as Internet Explorer) may take a while before it fully/partially  supports CSS3 W3C recommendations.</p>
<p><img src="http://images.sixrevisions.com/2009/08/13-02_roundedcorners.jpg" width="550" height="300" alt="Rounded corners without the HTML mess" /></p>
<p>Many designers know how to create rounded corners using CSS,  HTML, and a bunch of images, but these techniques cause a lot of HTML/CSS  clutter.</p>
<p>Below is an example of some cluttered HTML used to create  rounded corners.</p>
<pre>&lt;div class=&quot;roundedbox&quot;&gt;
  &lt;div class=&quot;hd&quot;&gt;
  &lt;div class=&quot;c&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;bd&quot;&gt;
  &lt;div class=&quot;c&quot;&gt;
    &lt;div class=&quot;s&quot;&gt;
      &lt;-- main content goes here --&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;ft&quot;&gt;
  &lt;div class=&quot;c&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</pre>
<p>That&#8217;s quite a lot of code for one rounded box. Most  designers know that it can be difficult to sift though HTML code like this,  especially when trying to alter a page that use several rounded corners.</p>
<p>A solution to our problem is simple though &#8211; instead of  writing all of the extra HTML <code>div</code>s each time we need a new rounded box,  we can simply have jQuery do all the work for us (by way of DOM manipulation).</p>
<p>This useful technique is from <a href="http://15daysofjquery.com/wrap-it-up-pretty-corners/13/">Day 13</a> of  the <a href="http://15daysofjquery.com/">15 Days of jQuery</a> site. For a full  tutorial or more detail on how it works, head on over there.</p>
<p>By utilizing the script below, we can automatically add the  extra <code>div</code>s where needed.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
    $(&quot;div.<strong>roundbox</strong>&quot;).wrap('
      &lt;div class=&quot;roundedbox&quot;&gt;'+
      ' &lt;div class=&quot;bd&quot;&gt;'+
      '   &lt;div class=&quot;c&quot;&gt;'+
      '     &lt;div class=&quot;s&quot;&gt;'+
      '     &lt;/div&gt;'+
      '  &lt;/div&gt;'+
      ' &lt;/div&gt;'+
      '&lt;/div&gt;');
});
&lt;/script&gt;</pre>
<p>The use of <code>div.roundbox</code> in the snippet above is key.  Now, instead of writing out all of those <code>divs</code> every time we need to  create a new rounded box, all we have to do is use the class <code>roundbox</code>; jQuery  will traverse the DOM to find all elements that has that class value and will  automatically wrap it around <code>div</code>&#8217;s.</p>
<p>Here&#8217;s a sample <code>div</code> HTML structure:</p>
<pre>&lt;div class=&quot;<strong>roundbox</strong>&quot;&gt;
  &lt;-- main content goes here --&gt;
&lt;/div&gt;</pre>
<p>Of course, you&#8217;ll still have to use some CSS to get the  rounded corner images to work, and Jack Born of 15 Days of jQuery provides you  with a <a href="http://www.schillmania.com/projects/dialog/">downloadable  package</a> that includes the auxiliary source files you&#8217;ll need.</p>
<h3>3. Scrolling Content</h3>
<p>Animated scrolling in jQuery can be used to create image  carousels and to simplify a design by being able to display more content in a  smaller space.</p>
<p>Below is an example of a jQuery plugin called <a href="http://www.flowplayer.org/tools/scrollable.html">Scrollable</a> (check  out the demo on that page to see the plugin in action).</p>
<p><a href="http://www.flowplayer.org/tools/scrollable.html"><img src="http://images.sixrevisions.com/2009/08/13-03_scrollingcontent.jpg" width="550" height="249" alt="Scrolling Content" /></a></p>
<p>There are tons of plugins and tutorials on the web for how  to create scrollable content, the Scrollable plugin being one of them.</p>
<p>To help you scroll up and down a web page in an animated way,  check out the tutorial called <em><a href="http://blog.freelancer-id.com/index.php/2009/03/26/scroll-window-smoothly-in-jquery">Scroll  window smoothly in jQuery</a></em> on <a href="http://blog.freelancer-id.com/index.php">Freelancer ID Blog</a>.</p>
<p>In order to tell jQuery to scroll, we need a section in a  web page to scroll up or down to (<code>ScrollTarget</code>).</p>
<pre>&lt;div class=&quot;<strong>ScrollTarget</strong>&quot;&gt;
  &lt;p&gt;After a scroll button is clicked, jQuery will animate the
  page to this point.&lt;/p&gt;
&lt;/div&gt;</pre>
<p>Next, we can use any HTML element to use as a trigger to  call a function called <code>scroll()</code>, such as an image or input button to tell  the browser to scroll to the above <code>div</code> when clicked.</p>
<p><strong>Example of a input button:</strong></p>
<pre>&lt;input <strong>onclick=&quot;scoll();&quot;</strong> type=&quot;button&quot; value=&quot;Scroll&quot; /&gt;</pre>
<p><strong>Example of an image:</strong></p>
<pre>&lt;img <strong>onclick=&quot;scoll();&quot;</strong> src=&quot;images/scroll.jpg&quot; alt=&quot;Scroll&quot; /&gt;</pre>
<p>Here is the code for the <code>scroll()</code> function.</p>
<pre>function <strong>scroll()</strong>{
  $('html, body').animate({
    scrollTop: $(&quot;.ScrollTarget&quot;).offset().top
  }, 2000);
}</pre>
<p>The downside to this technique is that it uses an <code>onclick</code>  property which is bad practice if you&#8217;re interested in obeying unobtrusive  JavaScript principles. So, you can modify the element&#8217;s markup in such a way  that it has a <code>class</code> property value of, for example, <code>scrollTrigger</code>:</p>
<pre>&lt;input class=&quot;<strong>scrollTrigger</strong>&quot; type=&quot;button&quot; value=&quot;Scroll&quot; /&gt;</pre>
<p>And then simply replace the above <code>scroll()</code> function to  this script below:</p>
<pre><strong>$('.scrollTrigger').click(function()</strong>{
  $('html, body').animate({
    scrollTop: $(&quot;.ScrollTarget&quot;).offset().top
  }, 2000);
<strong>});</strong>
</pre>
<h3>4. CSS Style Switcher</h3>
<p>Switching themes is a great way to vary the theme and look  of a web page. Switching stylesheets may be necessary to accommodate different  screen resolutions, or perhaps to allow users to pick a light background  alternative to a dark design.</p>
<p><img src="http://images.sixrevisions.com/2009/08/13-04_styleswitcher.jpg" width="550" height="300" alt="CSS Style Switcher" /></p>
<p>It&#8217;s quite easy to do (really). Include the following jQuery  script to the <code>&lt;head&gt;</code> of your HTML file.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
  $(&quot;.<strong>styleswitch</strong>&quot;).click(function() {
    $('link[rel=stylesheet]').attr('<strong>href</strong>' , $(this).attr('<strong>rel</strong>')); 
  });
&lt;/script&gt;</pre>
<p>To give options to the user for switching styles, just  assign the <code>styleswitch</code> class to an HTML element (<code>a</code> elements would  be good candidates), using the <code>rel</code> attribute to reference the location of your stylesheets.</p>
<pre>&lt;a href=&quot;#&quot; class=&quot;<strong>styleswitch</strong>&quot; rel=&quot;dark.css&quot;&gt;Dark&lt;/a&gt;
&lt;a href=&quot;#&quot; class=&quot; <strong>styleswitch</strong> &quot; rel=&quot;light.css&quot;&gt;Light&lt;/a&gt;
</pre>
<p>For example, if this is how you reference your default  stylesheet:</p>
<pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;<strong>dark.css</strong>&quot; type=&quot;text/css&quot;&gt;
</pre>
<p>Clicking on the second link above will modify the DOM in  such a way that the <code>href</code> attribute will take on the value of  <code>light.css</code>.</p>
<h3>5. Resizing text dynamically</h3>
<p>This common trick among designers can make it easy for users  to control how big or small they see the text on a web page without having to modify  their web browser settings.</p>
<p><img src="http://images.sixrevisions.com/2009/08/13-05_textresizer.jpg" width="550" height="238" alt="Resizing text dynamically" /></p>
<p>Using links to increase, decrease, or reset the text size of  a webpage can easily be implemented using jQuery.</p>
<p>The following snippet from <a href="http://www.queness.com/post/126/useful-and-handy-jquery-tips-and-tricks">Queness</a> will do the trick.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
  <strong>var section</strong> = new Array('<strong>span</strong>','<strong>.section2</strong>'); 
  section = section.join(',');

  // Reset Font Size
  var originalFontSize = $(section).css('font-size');
  $(&quot;<strong>.resetFont</strong>&quot;).click(function(){
    $(section).css('font-size', originalFontSize); 
  });

  // Increase Font Size
  $(&quot;<strong>.increaseFont</strong>&quot;).click(function(){
    var currentFontSize = $(section).css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
    $(section).css('font-size', newFontSize);
    return false;
  });

  // Decrease Font Size
  $(&quot;<strong>.decreaseFont</strong>&quot;).click(function(){
    var currentFontSize = $(section).css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.8;
    $(section).css('font-size', newFontSize);
    return false;
  });
});
&lt;/script&gt;</pre>
<p>In the code above, you will notice an array called  <code>section</code>. This defines which HTML elements can be resized.</p>
<p>From there, we can use basic HTML to create text-resizing  links.</p>
<pre>&lt;a class=&quot;<strong>increaseFont</strong>&quot;&gt;+&lt;/a&gt; | &lt;a class=&quot;<strong>decreaseFont</strong>&quot;&gt;-&lt;/a&gt;
| &lt;a class=&quot;<strong>resetFont</strong>&quot;&gt;=&lt;/a&gt;

&lt;<strong>span</strong>&gt;Font size can be changed in this section&lt;/<strong>span</strong>&gt;
&lt;div class=&quot;<strong>section1</strong>&quot;&gt;This won't be affected&lt;/div&gt;
&lt;div class=&quot;<strong>section2</strong>&quot;&gt;This one is adjustable too!&lt;/div&gt;</pre>
<h3>6. Animated accordions for interactive content displays</h3>
<p>Accordions that use jQuery can take on many forms, from  displaying only necessary content, to creating expandable/collapsible  navigation menus.</p>
<p>Designers can create accordion menus with some pretty cool  animation effects using jQuery.</p>
<p><a href="http://www.webdesignerwall.com/demo/jquery/accordion1.html"><img src="http://images.sixrevisions.com/2009/08/13-06_accordionmenu.jpg" width="550" height="242" alt="Animated accordion." /></a></p>
<p>To view a demo of an accordion in action, check out <a href="http://www.webdesignerwall.com/demo/jquery/accordion1.html">the accordion  over on WebDesignerWall</a>.</p>
<p>Using the jQuery script below, we can use a mixture of <code>&lt;h3&gt;</code>  and <code>&lt;p&gt;</code>  elements to hide and  show the paragraphs below the heading tags.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
  $(&quot;.accordion p&quot;).hide();
  $(&quot;.accordion h3&quot;).click(function(){
    $(this).next(&quot;p&quot;).slideToggle(&quot;slow&quot;)
     .siblings(&quot;p:visible&quot;).slideUp(&quot;slow&quot;);
    $(this).toggleClass(&quot;active&quot;);
    $(this).siblings(&quot;h3&quot;).removeClass(&quot;active&quot;);
  });
});
&lt;/script&gt;</pre>
<p><strong>Note</strong>: If you&#8217;d like a faster animation movement, modify the <code>slideToggle</code> and <code>slideUp</code> methods so that it passes either the  strings <code>'normal'</code> or <code>'fast'</code>, or simply use an integer in millisecond  units (such as <code>.slideUp(500)</code> for a half -second transition).</p>
<p>Below is the HTML we need to use. As you can see, it&#8217;s  pretty straightforward and all we need to have is the <code>div.accordion</code>  element, and <code>&lt;h3&gt;</code>/<code>&lt;p&gt;</code> pairs inside it.</p>
<pre>&lt;div class=&quot;<strong>accordion</strong>&quot;&gt;
  &lt;<strong>h3</strong>&gt;Item One&lt;/<strong>h3</strong>&gt;
  &lt;<strong>p</strong>&gt;Lorem ipsum dolor sit amet.&lt;/<strong>p</strong>&gt;
  &lt;h3&gt;Item Number Two&lt;/h3&gt;
  &lt;p&gt;Lorem ipsum dolor sit amet.&lt;/p&gt;
  &lt;h3&gt;Here is Item Three&lt;/h3&gt;
  &lt;p&gt;Lorem ipsum dolor sit amet.&lt;/p&gt;
&lt;/div&gt;</pre>
<p>Take a closer look at this and some other jQuery tricks over  at <a href="http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/">WebDesignerWall</a>.</p>
<h3>7. Tooltips to convey contextual messages on an element of interest</h3>
<p>Tooltips are an easy way to give users more information when  they hover on a particular page element. By hovering over an element of choice,  the user can view a simple tooltip that pops up displaying links, content, a  larger image, and other contextual information that they might find useful.</p>
<p><a href="http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery"><img src="http://images.sixrevisions.com/2009/08/13-07_tooltip.jpg" width="550" height="396" alt="Tooltips to convey contextual messages on an element of interest" /></a></p>
<p>The image above is actually an example of a demo page in  action (from <a href="http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery">CSSGlobe</a>).  To download this script set, head on over to their write-up of it called <em><a href="http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery">Easiest  Tooltip and Image Preview Using jQuery</a></em>.</p>
<p>Here is the HTML markup you need, which, as you can see  follows unobtrusive JavaScript best practices by using a class  (<code>.preview</code>)to indicate which elements will have tooltips.</p>
<pre>&lt;a href=&quot;image.jpg&quot; class=&quot;<strong>preview</strong>&quot; title=&quot;Image&quot;&gt;Preview&lt;/a&gt;
</pre>
<h3>8. Modal windows to replace pop-up windows</h3>
<p>Modal windows can be used to display images, content, and  even iFrames.</p>
<p><img src="http://images.sixrevisions.com/2009/08/13-08_dialogbox.jpg" width="550" height="490" alt="Modal windows to replace pop-up windows" /></p>
<p>A dialog box like this takes more than just a few snippets  of code, it takes an entire tutorial.  Above  is an image of what the <a href="http://net.tutsplus.com/freebies/lightboxes/jquery-lightbox-2/">NetTuts+  tutorial for creating a modal dialog box</a> can do. It is a great tutorial to  follow if you would like to make your own, and customize it along the way.</p>
<h4>jQuery Plugins for Modal Windows</h4>
<p>Instead of creating your own jQuery script for modal windows,  there are plenty of plugins that you can use to get the job done; below are  just a few of them.</p>
<p><a href="http://orderedlist.com/demos/fancy-zoom-jquery/"><em>FancyZoom</em></a></p>
<p><a href="http://orderedlist.com/demos/fancy-zoom-jquery/"><img src="http://images.sixrevisions.com/2009/08/13-09_fancyzoom.jpg" width="550" height="428" alt="FancyZoom" /></a></p>
<p><a href="http://www.pedrolamas.com/projectos/jquery-lightbox-en/">Wordpress jQuery  Lightbox Plugin</a></p>
<p><a href="http://www.pedrolamas.com/projectos/jquery-lightbox-en/"><img src="http://images.sixrevisions.com/2009/08/13-10_wordpresslightbox.jpg" width="550" height="258" alt="Wordpress jQuery Lightbox Plugin" /></a></p>
<p><a href="http://www.ericmmartin.com/simplemodal/">SimpleModal</a></p>
<p><a href="http://www.ericmmartin.com/simplemodal/"><img src="http://images.sixrevisions.com/2009/08/13-11_simplemodal.jpg" width="550" height="459" alt="SimpleModal" /></a></p>
<h3>9. Tabbed interfaces for displaying content</h3>
<p>Tabs are a great way to save space, just like an accordion.  With a rise in minimalist designs, designers need new ways to decrease the  space that web page content can take up. Tabs are also a great way to organize  information on a web page, making the design much more user-friendly. The image  below showcases a tabbed area demonstration using the <a href="http://jqueryui.com/demos/tabs/#default">jQuery UI tabs</a>.</p>
<p><img src="http://images.sixrevisions.com/2009/08/13-12_tabs.jpg" width="550" height="309" alt="Tabbed interfaces for displaying content" /></p>
<h3>10. Using  jQuery UI for easy widget  implementation</h3>
<p>The last &quot;trick&quot; for designers is easy: take a  look at (and learn about) the jQuery User Interface (<a href="http://jqueryui.com/">jQuery UI</a>).</p>
<p><a href="http://jqueryui.com/"><img src="http://images.sixrevisions.com/2009/08/13-14_jqueryui.jpg" width="550" height="507" alt="Using jQuery UI for easy widget implementation" /></a></p>
<p>Basically, jQuery UI extends the jQuery core library to give  you access to useful and common UI components (widgets) such as date pickers,  accordion, tabs, sliders, and more.</p>
<p>To make things easier for designers wanting to save time and  coding requirements, they have provided a nifty tool for quickly testing and  creating your own jQuery UI themes, aptly called <a href="http://jqueryui.com/themeroller/">ThemeRoller</a>, (which is also  available as a <a href="http://jqueryui.com/themeroller/developertool/">Firefox  bookmarklet</a>).</p>
<p>Needless to say that there are plenty of features that come  from jQuery UI that let designers &quot;<em>Code  Less, Do More.</em>&quot;</p>
<h3>Wrapping Up</h3>
<p>Many visual effects and impressive interaction can be  achieved using jQuery. The above ten tips may be common and incredibly useful,  but the power of jQuery does not stop there. I hope that this post has gotten  you interested enough to keep exploring and learning more about this  designer-friendly JavaScript library.</p>
<p>Please share any <em>additional  plugins</em>, <em>tutorials</em>, and <em>jQuery tricks</em> that may help your fellow  web designers in the comments.</p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/">Create  a Slick and Accessible Slideshow Using jQuery</a></li>
<li><a href="http://sixrevisions.com/javascript/40-exceptional-jquery-interface-techniques-and-tutorials/">40  Exceptional jQuery Interface Techniques and Tutorials</a></li>
<li><a href="http://sixrevisions.com/resources/14-jquery-plugins-for-working-with-images/">14  jQuery Plugins for Working with Images</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and <a href="http://sixrevisions.com/category/web_design/">Web Design</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/kayla_knight_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Kayla Knight</strong> is a 20 year old college student, part-time web developer, freelancer, and blogger. In her spare time she maintains<strong> <a href="http://webitect.net/">Webitect.net</a></strong>, a resource blog for webmasters. She also writes for top blogs like Smashing Magazine and Web Designer Depot. You can get a hold of her through her blog, or <strong>follow her on twitter</strong> &#8211; <strong>@<a href="https://twitter.com/Webitect">Webitect</a></strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/10-easy-jquery-tricks-for-designers/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>20 Fresh jQuery Plugins to Enhance your User Interface</title>
		<link>http://sixrevisions.com/javascript/20-fresh-jquery-plugins-to-enhance-your-user-interface/</link>
		<comments>http://sixrevisions.com/javascript/20-fresh-jquery-plugins-to-enhance-your-user-interface/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 22:00:07 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=1611</guid>
		<description><![CDATA[In this article, we share with you a list of 20 useful jQuery plugins that were released recently that could help you for your next web project.]]></description>
			<content:encoded><![CDATA[<p>The great thing about <a href="http://jquery.com/">jQuery</a> is that talented jQuery developers often release new and useful plugins on a regular basis. jQuery plugins are not only easy to implement, but easy to maintain even when used throughout large sites.</p>
<p>In this article, we share with you <strong>a list of 20 useful jQuery plugins that were released recently</strong> that could help you for your next web project. There are various types of plugins here such as modal windows, image galleries, auto complete for form input, bookmarking functions, preloaders, and more. Enjoy!</p>
<h3>1. <a href="http://www.ericmmartin.com/simplemodal/" target="_blank">SimpleModal</a></h3>
<p>This jQuery plugin is a flexible and straightforward way of providing <a href="http://en.wikipedia.org/wiki/Modal_window">modal window</a> functionality on your site.</p>
<p><a href="http://www.ericmmartin.com/simplemodal/"><img src="http://images.sixrevisions.com/2009/09/12-01_simple_modal.jpg" width="550" height="304" alt="SimpleModal" /></a><span class="figure-caption"><a href="http://www.ericmmartin.com/simplemodal/" target="_blank">SimpleModal Demo</a></span></p>
<p><span id="more-1611"></span></p>
<h3>2. <a href="http://www.catchmyfame.com/2009/05/02/jquery-panel-gallery-plugin/" target="_blank">Panel Gallery </a></h3>
<p><em>Panel Gallery</em> is an image slideshow with a unique transitional effect. It transitions to another image in a sequential panel manner.</p>
<p><a href="http://www.catchmyfame.com/2009/05/02/jquery-panel-gallery-plugin/"><img src="http://images.sixrevisions.com/2009/09/12-05_panel_gallery.jpg" width="550" height="265" alt="Panel Gallery " /></a><span class="figure-caption"><a href="http://www.catchmyfame.com/jquery/demo/2/" target="_blank">Panel Gallery Demo</a></span></p>
<h3>3. <a href="http://code.google.com/p/jquery-gallery-plugin/" target="_blank">Easy Image Gallery </a></h3>
<p>Creating <a href="http://sixrevisions.com/resources/14-jquery-plugins-for-working-with-images/" title="14 jQuery Plugins for Working with Images">image thumbnail galleries</a> is a snap when you implement the <em>Easy Image Gallery jQuery</em> plugin into your site&#8217;s template.</p>
<p><a href="http://code.google.com/p/jquery-gallery-plugin/"><img src="http://images.sixrevisions.com/2009/09/12-03_easy_image_gallery.jpg" width="550" height="367" alt="Easy Image Gallery " /></a><span class="figure-caption"><a href="http://www.mudaimemo.com/p/gallery/" target="_blank">Easy Image Gallery Demo</a></span></p>
<h3>4. <a href="http://nyromodal.nyrodev.com/" target="_blank">nyromModal</a></h3>
<p><em>nyromModal</em> is a useful jQuery plugin that has a robust set of features and options for you to truly create a customized modal window for your web pages.</p>
<p><a href="http://nyromodal.nyrodev.com/"><img src="http://images.sixrevisions.com/2009/09/12-02_nyromodal.jpg" width="550" height="338" alt="nyromModal" /></a><span class="figure-caption"><a href="http://nyromodal.nyrodev.com/#demos" target="_blank">nyromModal Demo</a></span></p>
<h3>5. <a href="http://pikachoose.com/" target="_blank">PikaChoose</a></h3>
<p><em>PikaChoose</em> is a super lightweight image gallery that&#8217;s a cinch to integrate into your website. You can see it in action on the <a href="http://belvedereinc.net/">Belvedere Inc</a> website.</p>
<p><a href="http://pikachoose.com/"><img src="http://images.sixrevisions.com/2009/09/12-04_pikachoose.jpg" width="550" height="426" alt="PikaChoose" /></a><span class="figure-caption"><a href="http://pikachoose.com/" target="_blank">PikaChoose Demo</a></span></p>
<h3>6. <a href="http://www.ferretarmy.com/files/jQuery/ImageOverlay/ImageOverlay.html" target="_blank">Image Overlay Plugin</a></h3>
<p>The <em>Image Overlay Plugin</em> lets you present more information about your images. Hovering over an image reveals associated text on top of it.</p>
<p><a href="http://www.ferretarmy.com/files/jQuery/ImageOverlay/ImageOverlay.html"><img src="http://images.sixrevisions.com/2009/09/12-06_image_overlay.jpg" width="550" height="288" alt="Image Overlay Plugin" /></a><span class="figure-caption"><a href="http://www.ferretarmy.com/files/jQuery/ImageOverlay/ImageOverlay.html">Image Overlay Plugin Demo</a></span></p>
<h3>7. <a href="http://odyniec.net/projects/imgareaselect/" target="_blank">imgAreaSelect</a></h3>
<p>If you&#8217;re creating a web app that supports image cropping, this can be the client-side function that lets your users select rectangular areas of an image.</p>
<p><a href="http://odyniec.net/projects/imgareaselect/"><img src="http://images.sixrevisions.com/2009/09/12-07_img_area_select.jpg" width="550" height="306" alt="imgAreaSelect" /></a><span class="figure-caption"><a href="http://odyniec.net/projects/imgareaselect/examples.html" target="_blank">ImgAreaSelect Demo</a></span></p>
<h3>8. <a href="http://www.careers.manchester.ac.uk/dynamic/sandbox/jQueryPlugins/SimpleMenu/" target="_blank">SimpleMenu</a></h3>
<p>If you need a simple, lightweight, and barebones <a href="http://sixrevisions.com/javascript/20-excellent-javascript-navigation-techniques-and-examples/">JavaScript-based navigation menu</a>, <em>SimpleMenu</em> is the jQuery plugin of your dreams.</p>
<p><a href="http://www.careers.manchester.ac.uk/dynamic/sandbox/jQueryPlugins/SimpleMenu/"><img src="http://images.sixrevisions.com/2009/09/12-09_simple_menu.jpg" width="550" height="301" alt="SimpleMenu" /></a><span class="figure-caption"><a href="http://www.careers.manchester.ac.uk/dynamic/sandbox/jQueryPlugins/SimpleMenu/" target="_blank">SimpleMenu Demo</a></span></p>
<h3>9. <a href="http://www.hotajax.org/demo/jquery/SlideBox/SlideBox/index.html" target="_blank">SlideBox</a></h3>
<p>Do you need a sliding div panel at the top (or bottom) of web pages that can contain more links or your login/sign-in feature? Check out <em>SlideBox</em>.</p>
<p><a href="http://www.hotajax.org/demo/jquery/SlideBox/SlideBox/index.html"><img src="http://images.sixrevisions.com/2009/09/12-08_slidebox.jpg" width="550" height="246" alt="SlideBox" /></a><span class="figure-caption"><a href="http://www.hotajax.org/demo/jquery/SlideBox/SlideBox/index.html" target="_blank">SlideBox Demo</a></span></p>
<h3>10. <a href="http://www.codenothing.com/archives/jquery/single-drop-down-menu/" target="_blank">Single Drop Down Menu</a></h3>
<p><em>Single Drop Down Menu</em> (also known as <em>Single-ddm</em>) is a quick and hassle-free way of implementing multi-level navigation menus that leverage <a href="http://sixrevisions.com/category/javascript/" title="Six Revisions JavaScript category">JavaScript</a>.</p>
<p><a href="http://www.codenothing.com/archives/jquery/single-drop-down-menu/"><img src="http://images.sixrevisions.com/2009/09/12-10_simple_drop.jpg" width="550" height="220" alt="Single Drop Down Menu" /></a><span class="figure-caption"><a href="http://www.codenothing.com/demos/2009/single-ddm/index.html" target="_blank">Single Drop Down Menu Demo</a></span></p>
<h3>11. <a href="http://www.codenothing.com/archives/jquery/auto-complete/" target="_blank">Auto Complete</a></h3>
<p>Are you trying to build a custom search feature for a site? The <em>Auto Complete</em> jQuery plugin can supercharge your form inputs with additional user feature.</p>
<p><a href="http://www.codenothing.com/archives/jquery/auto-complete/"><img src="http://images.sixrevisions.com/2009/09/12-12_auto_complete.png" width="550" height="291" alt="Auto Complete" /></a><span class="figure-caption"><a href="http://www.codenothing.com/archives/jquery/auto-complete/" target="_blank">Auto Complete Demo</a></span></p>
<h3>12. <a href="http://oneupcode.com/?p=15" target="_blank">jQuery Iconize</a></h3>
<p><em>jQuery Iconize</em> allows you to reduce or expand page elements into an &quot;icon state&quot;, providing your web app a user-friendly way of minimizing page objects.</p>
<p><a href="http://oneupcode.com/?p=15"><img src="http://images.sixrevisions.com/2009/09/12-13_iconize.jpg" width="550" height="237" alt="jQuery Iconize" /></a><span class="figure-caption"><a href="http://oneupcode.com/files/iconize/demo3.html" target="_blank">jQuery Iconize Demo</a></span></p>
<h3>13. <a href="http://www.codenothing.com/archives/jquery/inline-text-edit/" target="_blank">Inline Text Edit</a></h3>
<p>Web developers looking to provide users with a basic in-page text editor should take a look at the <em>Inline Text Edit</em> jQuery plugin.</p>
<p><a href="http://www.codenothing.com/archives/jquery/inline-text-edit/"><img src="http://images.sixrevisions.com/2009/09/12-11_inline_text-edit.jpg" width="550" height="312" alt="Inline Text Edit" /></a><span class="figure-caption"><a href="http://www.codenothing.com/demos/2009/inline-edit/index.html" target="_blank">Inline Text Edit Demo</a></span></p>
<h3>14. <a href="http://arkus.malopolska.pl/skryptoplikacje/jquery/demos/pfeloader/" target="_blank">PfeLoader</a></h3>
<p>This jQuery plugin allows you to display a progress bar for page components that are being downloaded &#8211; useful for image galleries that share large-scale photos.</p>
<p><a href="http://arkus.malopolska.pl/skryptoplikacje/jquery/demos/pfeloader/"><img src="http://images.sixrevisions.com/2009/09/12-16_preloading.jpg" width="550" height="327" alt="PfeLoader" /></a><span class="figure-caption"><a href="http://arkus.malopolska.pl/skryptoplikacje/jquery/demos/pfeloader/" target="_blank">PfeLoader Demo</a></span></p>
<h3>15. <a href="http://labs.d-xp.com/growl/" target="_blank">Growl</a></h3>
<p><em>Growl</em> allows you to present DOM-inserted elements (divs by default) that are perfect for user warnings, messages, and status update notifications.</p>
<p><a href="http://labs.d-xp.com/growl/"><img src="http://images.sixrevisions.com/2009/09/12-17_growl.jpg" width="550" height="258" alt="Growl" /></a><span class="figure-caption"><a href="http://labs.d-xp.com/growl/" target="_blank">Growl Demo</a></span></p>
<h3>16. <a href="http://keith-wood.name/bookmark.html" target="_blank">jQuery Bookmark</a></h3>
<p>Sharing your content in social news and networking sites requires little else than implementing the <em>jQuery Bookmark</em> plugin.</p>
<p><a href="http://keith-wood.name/bookmark.html"><img src="http://images.sixrevisions.com/2009/09/12-14_bookmark.jpg" width="550" height="220" alt="jQuery Bookmark" /></a><span class="figure-caption"><a href="http://keith-wood.name/bookmark.html" target="_blank">jQuery Bookmark Demo</a></span></p>
<h3>17. <a href="http://plugins.jquery.com/project/moatext" target="_blank">Mouse Over Animation for Text</a></h3>
<p><em>MOAText</em> is a spiffy jQuery plugin for giving you the ability to animate HTML text triggered when the mouse cursor hovers over them.</p>
<p><a href="http://plugins.jquery.com/project/moatext"><img src="http://images.sixrevisions.com/2009/09/12-15_mouseover_animatoon.jpg" width="550" height="245" alt="Mouse Over Animation for Text" /></a><span class="figure-caption"><a href="http://labs.bitmeister.jp/moamoa/demo.html" target="_blank">MOAText Demo</a></span></p>
<h3>18. <a href="http://azoffdesign.com/plugins/js/overscroll" target="_blank">OverScroll</a></h3>
<p><em>OverScroll</em> lets you move around by holding down a mouse button and moving it, similar to how the iPhone allows you to move around a screen by finger gestures.</p>
<p><a href="http://azoffdesign.com/plugins/js/overscroll"><img src="http://images.sixrevisions.com/2009/09/12-18_overscroll.jpg" width="550" height="342" alt="OverScroll" /></a><span class="figure-caption"><a href="http://azoffdesign.com/plugins/js/overscroll" target="_blank">OverScroll Demo</a></span></p>
<h3>19. <a href="http://plugins.jquery.com/project/jqDialog" target="_blank">jQDialog</a></h3>
<p><em>jQDialog</em> is a jQuery plugin for exhibiting unobtrusive modal windows for in-page notifications that can replace the <code>alert()</code>, <code>prompt()</code>, and <code>confirm()</code> JavaScript functions.</p>
<p><a href="http://plugins.jquery.com/project/jqDialog"><img src="http://images.sixrevisions.com/2009/09/12-19_jqdialog.jpg" width="550" height="232" alt="jQDialog" /></a><span class="figure-caption"><a href="http://kailashnadh.name/code/jqdialog/" target="_blank">jQDialog Demo</a></span></p>
<h3>20. <a href="http://www.uploadify.com/" target="_blank">Uploadify</a></h3>
<p><em>Uploadify</em> is a package written on top of jQuery that gives you both the client-side and server-side functionality you&#8217;ll need to handle single-file and multi-file uploads.</p>
<p><a href="http://www.uploadify.com/"><img src="http://images.sixrevisions.com/2009/09/12-20_uploadify.jpg" width="550" height="423" alt="Uploadify" /></a><span class="figure-caption"><a href="http://www.uploadify.com/demo/" target="_blank">Uploadify Demo</a></span></p>
<p><strong>Can you suggest more plugins that we&#8217;ve overlooked? Have you used any of the plugins above?</strong> Share your thoughts and opinions in the comments!</p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/">Create a Slick and Accessible Slideshow Using jQuery</a></li>
<li><a href="http://sixrevisions.com/javascript/40-exceptional-jquery-interface-techniques-and-tutorials/">40 Exceptional jQuery Interface Techniques and Tutorials</a></li>
<li><a href="http://sixrevisions.com/resources/14-jquery-plugins-for-working-with-images/">14 jQuery Plugins for Working with Images</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and <a href="http://sixrevisions.com/category/user-interface/">User Interface</a></li>
</ul>
<h3>About the Author </h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/kawsar_ali_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Kawsar Ali</strong> is a web designer, graphic designer, and wannabe photographer based in NY, U.S. He&#8217;s also the founder of <a href="http://desizntech.info/"><strong>Desizntech</strong></a>, a site on tips about web design, Mac, PC and more. If you&#8217;d like to connect with him, you can follow him on <a href="https://twitter.com/desizntech" target="_blank"><strong>Twitter</strong></a> or at his<a href="http://i-exist.co.cc/" target="_blank"><strong> Personal Website</strong></a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/20-fresh-jquery-plugins-to-enhance-your-user-interface/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Build an Elastic Textarea with Ext JS</title>
		<link>http://sixrevisions.com/javascript/build-an-elastic-textarea-with-ext-js/</link>
		<comments>http://sixrevisions.com/javascript/build-an-elastic-textarea-with-ext-js/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 10:00:44 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=1582</guid>
		<description><![CDATA[In this article, I will guide you through the re-creation of this astonishing effect using Ext JS, and I bet you that you will be surprised to see how easy it is to do it.]]></description>
			<content:encoded><![CDATA[<p><img src="http://images.sixrevisions.com/2009/09/06-01_elastic_textarea_extjs.jpg" width="550" height="250" alt="Build an Elastic Textarea with Ext JS" /></p>
<p>Since it was first featured on Facebook, elastic textareas &#8211; <code>&lt;textarea&gt;</code> elements that automatically expand or shrink depending on how much text the user inputs &#8211; has become one of the coolest functional UI effects on the web. In this article, I will guide you through the re-creation of this astonishing effect using <a href="http://extjs.com/">Ext JS</a>, and I bet you that you will be surprised to see how easy it is to do it.</p>
<p><span id="more-1582"></span></p>
<h3>Live Demo</h3>
<p>Check out the example of what we will be creating by clicking on the following link.</p>
<ul>
<li><a href="http://sixrevisions.com/demo/elastic_textarea/index.html"><strong>Elastic Textarea demonstration</strong></a></li>
</ul>
<h3>What you will need </h3>
<p>For this tutorial, we will use the <a href="http://extjs.com/">Ext JS JavaScript framework</a> &#8211; my favorite framework for cross-browser web application development. I will explain the mechanics step by step so that if you prefer, you can implement the same programming logic using another JavaScript framework/library or with just JavaScript.</p>
<p>Only the <a href="http://extjs.com/products/extcore/">Ext Core</a> will be needed in this example.</p>
<h3>What is Ext JS?</h3>
<p>Ext JS describes itself as being a &quot;<em>cross-browser JavaScript library for building rich internet applications</em>&quot;. Although it&#8217;s true, this description is too succinct to describe this excellent JavaScript framework&#8217;s power and capabilities.</p>
<p>It&#8217;s the perfect tool for creating Rich Internet Applications (<a href="http://en.wikipedia.org/wiki/Rich_Internet_application" title="Wikipedia entry on Rich Internet Application">RIA</a>): it has a commanding effects library and an awesome GUI toolkit, providing you with tons of components that mimic desktop applications&#8217; fluidity and complexity on the web.</p>
<p>Ext JS is available in <strong>two flavors</strong>: <a href="http://extjs.com/products/extcore">Ext Core</a> and <a href="http://extjs.com/products/extjs">Ext JS</a>.</p>
<p><strong>Ext Core</strong> is the &quot;lite version&quot; of Ext JS, offering the same kind of functionalities you can find in other popular JS frameworks (like jQuery or MooTools). It&#8217;s licensed under the very permissive MIT license.  Some functions that are available in Ext JS are not available in Ext Core though &#8211; but in our instance, it&#8217;s quite alright.</p>
<p><strong>Ext JS</strong> is packed with a lot of extra features and lots of GUI gadgets. You can get it under one of the two licenses: under a GPL or a commercial license that waives the GPL restrictions. It&#8217;s extremely well <a href="http://extjs.com/deploy/dev/docs/">documented</a> with tons of <a href="http://extjs.com/deploy/dev/examples/samples.html">demos</a> and an easy to follow <a href="http://extjs.com/products/extcore/manual/">manual</a>. It also has great <a href="http://extjs.com/forum/">community support</a>, although they can be a bit harsh to beginners who don&#8217;t first search if their question has been answered already before asking questions. If you&#8217;re interested in learning about Ext JS more fully, check out this great tutorial that is available <a href="http://extjs.com/learn/Tutorial:Introduction_to_Ext_2.0">here</a>.</p>
<h3>The Issue</h3>
<p>Unfortunately, there is no <code>textarea.contentHeight</code> or similar method, so forget about a direct way to get the text height.</p>
<p>&quot;So how do I make the <code>textarea</code> grow and shrink?&quot;</p>
<p>A possible approach to find a <code>textarea</code>&#8217;s height is to get the font size and textarea width and count the number of characters typed. But then when you press the Enter key your calculations are messed up.</p>
<p>&quot;Ok, that&#8217;s not a problem&#8230; I can put the Enter key into the equation&quot; you might think, but then you have to think about CSS formatting (i.e. padding, line height, or font size).</p>
<p>You see how this can become a nightmare in no time?</p>
<p><strong>Don&#8217;t despair: there is an easy way using Ext JS!</strong></p>
<h3>The Trick</h3>
<p>To make the <code>textarea</code> grow or shrink, you need to get its content&#8217;s height and take into account the CSS styles that affect text formatting like <code>font-size</code>, <code>line-height</code>, etc.</p>
<p>The trick to get text height is to mimic the <code>textarea</code> contents in a hidden <code>div</code>.</p>
<p>To get a decent effect, we will also limit the textarea minimum and maximum sizes, there is no beauty in a 0-px height <code>textarea</code>.</p>
<p>Alright, it&#8217;s time to get our hands dirty.</p>
<h3>Step 1: Laying down the foundations</h3>
<p>First step is to create a function and set up some control variables; we shall name this function <code>elasticTextArea</code>.</p>
<p>We also declare two extra functions that allow us to get and set all CSS styles at once.</p>
<pre>function <strong>elasticTextArea</strong> (elementId){
/*
 * This are two helper functions, they are declared here for convenience
 * so we can get and set all styles at once and because they are not
 * available in ext-core only in Ext JS
 */
 <strong>//available in Ext JS (not ext-core) as element.getStyles</strong>
 function getStyles(el, arguments){
  var ret = {};
  total = arguments.length;
  for (var n=0; n&lt; len;) {
   el.setStyle(styles[i++], styles[i++]);
    }
     } else if (Ext.isObject(styles)) {
     el.setStyle(styles);
   }
  }
 }
 <strong>//minimum and maximum textarea size</strong>
 var minHeight = 10;
 var maxHeight = 300;
 <strong>//increment value when resizing the textarea</strong>
 var growBy = 20 ;
 var el = Ext.get(elementId);</pre>
<h3>Step 2: Get the textarea CSS styles</h3>
<p>To get an accurate measurement, we need to get the textarea CSS styles that affect text formatting, and they are:</p>
<ul>
<li><code>padding</code></li>
<li><code>font-size</code> (and other font styles)</li>
<li><code>font-family</code></li>
<li><code>line-height</code></li>
<li><code>width</code></li>
</ul>
<pre><strong>//get textarea width</strong>
 var width = el.getWidth();
<strong>//current textarea styles</strong>
 var styles = el.getStyles('padding-top', 'padding-bottom', 'padding-left',
              'padding-right', 'line-height', 'font-size',
              'font-family', 'font-weight', 'font-style');
/<strong>/store textarea width into styles object to later apply them to the div</strong>
styles.width = width +'px';

<strong>//hide the textarea scrool to avoid flickering</strong>
el.setStyle('overflow', 'hidden');</pre>
<h3>Step 3: Create the hidden div</h3>
<p>And here&#8217;s where the magic begins. We start by creating a hidden container for the textarea contents.</p>
<p>We set its position to <code>absolute</code> &#8212; this way, the <code>div</code> is removed from the layout&#8217;s flow and positioned outside the visible area of the browser.</p>
<p><strong>Note</strong>: setting its <code>visibility</code> CSS attribute to <code>hidden</code> or its <code>display</code> to <code>none</code> causes some browsers not to recalculate its height, that&#8217;s why we opted for this method.</p>
<p>We also instruct the textarea to recalculate its height by re-running this function on every key stoke; another method is to run it at a specific interval, but I find it to be more resource-intensive and less elegant that way.
</p>
<pre> /<strong>/create the hidden div only if does not exists</strong>
 if(!this.div){
  <strong>//create the hidden div outside the viewport area</strong>
  this.div = Ext.DomHelper.append(Ext.getBody() || document.body, {
   'id':elementId + '-preview-div',
   'tag' : 'div',
   'style' : 'position: absolute; top: -100000px; left: -100000px;'
  }, true);
 <strong>//apply the textarea styles to the hidden div</strong>
 Ext.DomHelper.applyStyles(this.div, styles);
 <strong>//recalculate the div height on each key stroke</strong>
 el.on('keyup', function(){
  elasticTextArea(elementId);
 }, this);
}</pre>
<h3>Step 4: Copy textarea contents to the hidden div and get its height</h3>
<p>To ensure a correct measurement, we replace some special characters with their <a href="http://en.wikipedia.org/wiki/Character_encodings_in_HTML#HTML_character_entity_references">HTML character entities</a> and also append a space (<code>' '</code>) string to the new line to force its representation.</p>
<pre><strong>/* clean up textarea contents, so that no special chars are processed
 * replace \n with so that the enter key can trigger a height increase
 * but first remove all previous entries, so that the height measurement
 * can be as accurate as possible
 */</strong>
 this.div.update(
  el.dom.value.replace(//, '')
  .replace(/&lt;|&gt;/g, ' ')
  .replace(/&amp;/g,&quot;&amp;&quot;)
  .replace(/\n/g, '')
 );
 <strong>//finally get the div height</strong>
 var textHeight = this.div.getHeight();</pre>
<h3>Step 5: Resize the textarea</h3>
<p>In the last step, we give the textarea its new height. </p>
<pre>  <strong>//enforce textarea maximum and minimum size</strong>
  if ( (textHeight &gt; maxHeight ) &amp;&amp; (maxHeight &gt; 0) ){
   textHeight = maxHeight;
   el.setStyle('overflow', 'auto');
  }
  if ( (textHeight &lt; minHeight ) &amp;&amp; (minHeight &gt; 0) ){
   textHeight = minHeight ;
  }
 <strong>//resize the textarea</strong>
 el.setHeight(textHeight + growBy , true);
}</pre>
<h3>Try it out</h3>
<p>Wasn&#8217;t that simple? Save the JavaScript code we wrote as <strong>elasticTextarea.js</strong> or <a href="http://sixrevisions.com/demo/elastic_textarea/elastic_textarea.zip">download the source</a>, include Ext Core and the JavaScript library, and have fun.</p>
<p>To include the JS libraries:</p>
<pre>&lt;script type=&quot;text/JavaScript&quot; src=&quot;ext-core/ext-core.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/JavaScript&quot; src=&quot;elastic.js&quot;&gt;&lt;/script&gt;
</pre>
<p>The HTML for the text area:</p>
<pre>&lt;textarea id=&quot;ta&quot;&gt;&lt;/textarea&gt;</pre>
<p>To call the function (&#8217;ta&#8217; being the ID of the <code>textarea</code>):</p>
<pre>&lt;script type=&quot;text/JavaScript&quot;&gt;
 elasticTextArea(&quot;ta&quot;);
&lt;/script&gt;
</pre>
<h3>Conclusion</h3>
<p>The purpose of this article is to introduce you to Ext JS. If you know your JavaScript well, you might find that this code will only work for one textarea. If you&#8217;d like a more robust and flexible solution, get the Ext JS plugin that can be found over at <strong><a href="http://www.francodacosta.com/blog/extjs/elastic-textarea">my site</a></strong>.</p>
<p>Stay tuned for more Ext JS tutorials here on Six Revisions, written by <a href="http://www.francodacosta.com/blog/about/me">me</a>. Future tutorials will cover Ext JS plugins, and talk about more cool and easy-to-create UI effects using Ext JS RIA framework.</p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/web-development/a-guide-on-advanced-logging-and-benchmarking-with-firephp/">A Guide on Advanced Logging and Benchmarking with FirePHP</a></li>
<li><a href="http://sixrevisions.com/javascript/40-exceptional-jquery-interface-techniques-and-tutorials/">40 Exceptional jQuery Interface Techniques and Tutorials</a></li>
<li><a href="http://sixrevisions.com/javascript/promising_javascript_frameworks/">10 Promising JavaScript Frameworks</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/user-interface/">User Interface</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/nuno_francodacosta_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Nuno Franco da Costa</strong> is a web developer and sys admin. By day, he works at a design agency coordinating the development and sys admin teams where he developed a PHP MVC framework and a WEB 2 CMS. He loves to code and has a &quot;<em>getting things done</em>&quot; attitude. You can find over at his online presence <a href="http://www.francodacosta.com/"><strong>www.francodacosta.com</strong></a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/build-an-elastic-textarea-with-ext-js/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>10 Impressive JavaScript Animation Frameworks</title>
		<link>http://sixrevisions.com/javascript/10-impressive-javascript-animation-frameworks/</link>
		<comments>http://sixrevisions.com/javascript/10-impressive-javascript-animation-frameworks/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 22:35:01 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=1169</guid>
		<description><![CDATA[In this article, you will read about the top 10 JavaScript-based animation frameworks and libraries that will enable you to create engaging and captivating user experiences.]]></description>
			<content:encoded><![CDATA[<p>Complex and slick <strong>JavaScript-based animation</strong> has been made  easier with the emergence of frameworks and libraries that give developers the  ability to create stunning and eye-grabbing animation and transition effects that  make it easy these complex tasks.</p>
<p>In this article, you will read about the <strong>top 10  JavaScript-based animation frameworks and libraries</strong> that will enable you to  create engaging and captivating user experiences.</p>
<h3>1. <a href="http://fx.inetcat.com/">$fx</a></h3>
<p><a href="http://fx.inetcat.com/"><img src="http://images.sixrevisions.com/2009/07/02-01_fx.jpg" width="550" height="220" alt="$fx" /></a></p>
<p><span id="more-1169"></span></p>
<p><em>$fx</em> is a compact  and lightweight JavaScript animation library which extends native JavaScript  DOM methods with its own animation methods and functions. Its small file size  (weighing in at only 3.7 KB), hassle-free implementation, and low learning curve  makes $fx a powerful option for adding eye-popping animation effects to your  web projects. Check out the <a href="http://fx.inetcat.com/manuals.php#b3">Examples  section</a> on the <a href="http://fx.inetcat.com/manuals.php">Manuals page</a> to see the library in action.</p>
<h3>2. <a href="http://jsanim.com/">jsAnim</a></h3>
<p><a href="http://jsanim.com/"><img src="http://images.sixrevisions.com/2009/07/02-02_jsanim.png" width="550" height="220" alt="jsAnim" /></a></p>
<p>Created by web developer <a href="http://www.designbydolan.net/">Kevin Dolan</a>, <em>jsAnim</em> is a JavaScript animation framework for creating high-impact  and slick animation sequences for web interfaces. Crafted with standards and  best practices in mind, jsAnim allows you to create stunning animation effects  without sacrificing web accessibility of your web projects.</p>
<h3>3. <a href="http://scripty2.com/">scripty2</a></h3>
<p><a href="http://scripty2.com/"><img src="http://images.sixrevisions.com/2009/07/02-03_scripty2.jpg" width="550" height="220" alt="scripty2" /></a></p>
<p><em>scripty2</em> is a  flexible and lightweight JavaScript animation framework for developing  delicious visual effects. The project is still young (alpha), but you can  already see its impressive capabilities in the <a href="http://scripty2.com/demos/cards/">scripty2 demo page</a> which shows  examples that rival Flash-based objects in smooth, seamless, and complex  animations.</p>
<h3>4. <a href="http://gx.riccardodegni.net/">GX</a></h3>
<p><a href="http://gx.riccardodegni.net/"><img src="http://images.sixrevisions.com/2009/07/02-04_gx.png" width="550" height="220" alt="GX" /></a></p>
<p><em>GX</em>, developed by  Italian web developer <a href="http://www.riccardodegni.net/">Riccardo Degni</a>,  is a compact (10KB uncompressed animation effects library that puts strict web  standards and best practices at the forefront of its development philosophy.  Built on top of jQuery, but heavily influenced by MooTools development patterns,  you can customize your GX download to include only the parts you need, making  your scripts optimized for file size. Check out the <a href="http://gx.riccardodegni.net/demos/core">GX Demos</a> to see its  capabilities.</p>
<h3>5. <a href="http://visitmix.com/lab/glimmer">Glimmer</a></h3>
<p><a href="http://visitmix.com/lab/glimmer"><img src="http://images.sixrevisions.com/2009/07/02-05_glimmer.png" width="550" height="220" alt="Glimmer" /></a></p>
<p><em>Glimmer</em> is a  framework for easily creating interactive elements on your web pages. Glimmer  comes with wizards GUIs, reducing your coding requirements and guaranteeing  standardization across your projects. Check out the <a href="http://visitmix.com/labs/glimmer/samples/sequence.html">Image-Sequencer  demo</a> to see Glimmer’s animation capabilities. It’s written on top of the  popular <a href="http://jquery.com/">jQuery</a> library.</p>
<h3>6. <a href="http://www.berniecode.com/writing/animator.html">Animator.js</a></h3>
<p><a href="http://www.berniecode.com/writing/animator.html"><img src="http://images.sixrevisions.com/2009/07/02-06_animatorjs.png" width="550" height="220" alt="Animator.js" /></a></p>
<p><em>Animator.js</em> is a  class-based way for implementing JavaScript-based animation effects. Its design  and development principles follow <a href="http://www.ooad.org/">OOAD</a>,  which promotes maintainable and high-lifetime development of applications.  Thus, it syntax is prototypal and object-oriented, reminiscent of <a href="http://mootools.net/">MooTools</a> and <a href="http://www.prototypejs.org/">Prototype.js</a> syntax.</p>
<h3>7. <a href="http://www.scriptio.us/index.php">Scriptio</a></h3>
<p><a href="http://www.scriptio.us/index.php"><img src="http://images.sixrevisions.com/2009/07/02-07_scriptious.png" width="550" height="220" alt="Scriptio" /></a></p>
<p><em>Scriptio</em> is an  open source framework for animation and presentational elements to enhance and  enrich the learner’s web experience. Scriptio is easy to learn and its terse  syntax makes it great for fast prototyping. View the <a href="http://www.scriptio.us/examples.php">Scriptio Examples</a> page where you  will find eight cool demos that exemplify this framework’s abilities.</p>
<h3>8. <a href="http://processingjs.org/">Processing.js</a></h3>
<p><a href="http://processingjs.org/"><img src="http://images.sixrevisions.com/2009/07/02-08_processingjs.png" width="550" height="220" alt="Processing.js" /></a></p>
<p><em>Processing.js</em> is a fully featured  framework for scripting images, animation, and interaction developed by jQuery library  creator, <a href="http://ejohn.org/">John Resig</a>. Processing.js is a  JavaScript port of the open source <a href="http://en.wikipedia.org/wiki/Processing_(programming_language)">Processing</a> project. You should check out the <a href="http://processingjs.org/exhibition">Exhibits</a> page to see full-production implementations of Processing.js.</p>
<h3>9. <a href="http://aka-fotos.de/run/">Run</a><br />
</h3>
<p><a href="http://aka-fotos.de/run/"><img src="http://images.sixrevisions.com/2009/07/02-09_run.png" width="550" height="220" alt="Run" /></a> </p>
<p>For developers looking for a simple means of animating  content, <em>Run</em>, a universal JavaScript  animation framework, is the definitive way to go. Run emphasizes on ease-of-use  as shown by its intuitive syntax and copious amounts of <a href="http://aka-fotos.de/run/documentation.php">documentation</a>. Run has  also been tested on a wide array of web browsers, ensuring utmost cross-browser  compatibility. Head over to <a href="http://aka-fotos.de/run/examples.php">Run’s  Example page</a> to see the project in action.</p>
<h3>10. <a href="http://hyper-metrix.com/#Burst">Burst Engine</a></h3>
<p><a href="http://hyper-metrix.com/#Burst"><img src="http://images.sixrevisions.com/2009/07/02-10_burst.png" width="550" height="220" alt="Burst Engine" /></a></p>
<p><em>Burst Engine</em> is an open source vector animation framework  for HTML 5’s <a href="http://en.wikipedia.org/wiki/Canvas_(HTML_element)">Canvas</a> element. Burst provides smooth, slick, and complex animations that will surely  leave a memorable impression upon viewers. To see Burst in action, check out  the <a href="http://www.hyper-metrix.com/burst/development/doc/demos/Simple3DEngineOn2DCanvas.htm">3D  Engine</a> demo (and prepare to get very impressed).</p>
<h3>Related content</h3>
<ul>
<li><a href="http://sixrevisions.com/javascript/promising_javascript_frameworks/">10  Promising JavaScript Frameworks</a></li>
<li><a href="http://sixrevisions.com/javascript/graph_chart_plot_data_javascript/">Graphing/Charting  Data on Web Pages: JavaScript Solutions</a></li>
<li><a href="http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/">JavaScript  Debugging Techniques in IE 6</a></li>
<li>Related categories: <a href="http://sixrevisions.com/category/javascript/">JavaScript</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/10-impressive-javascript-animation-frameworks/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>JavaScript Debugging Techniques in IE 6</title>
		<link>http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/</link>
		<comments>http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/#comments</comments>
		<pubDate>Fri, 15 May 2009 16:27:35 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=851</guid>
		<description><![CDATA[Microsoft's Internet Explorer 6 is almost universally hated by web developers. It's hard to work with and support, but with a few techniques, you can make the process less painful.]]></description>
			<content:encoded><![CDATA[<p>Microsoft&#8217;s Internet Explorer 6 is almost universally hated by web developers. It&#8217;s hard to work with and support, but with a few solid techniques, you can make the process less painful. What &#8220;just works&#8221; in the majority of browsers will almost always require hours of tweaks and workarounds to get it working in IE6. With more and more users switching over to newer alternatives such as IE8, Safari and Firefox hopefully support for IE6 can be dropped sooner rather than later. In the mean time though many of us have to make sure our sites work in this awful browser.</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-18_javascript_debugging_leading.jpg" width="550" height="250" alt="JavaScript Debugging Techniques in IE 6" /></p>
<p><span id="more-851"></span></p>
<p>To make things worse, IE6 is extremely bad at helping developers diagnose problems. When a JavaScript error occurs, IE6&#8217;s default behaviour is to display a small error icon in the status bar. Extremely easy to miss!</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-01_status-bar-error.png" width="214" height="113" alt="Status Bar Error." /></p>
<p>Double clicking on this icon will display a popup, and if you then click the &#8220;Show Details&#8221; button you&#8217;ll get the actual details of the JavaScript error. Unfortunately the detailed error message can be quite cryptic, and probably not too much help in diagnosing the actual problem. Your best bet is to make a note of the line and column number of the problem and then look that up in the source code. Fortunately, with the help of Visual Studio and by changing a few IE settings, we can make it much easier on ourselves.</p>
<h3>Setting things up</h3>
<p>To enable JavaScript debugging in IE we need to change some default settings, which can be accessed from the Tools&gt; Internet Options menu, and then the Advanced tab. The image below shows the default IE6 settings, with the three settings we&#8217;re interested in highlighted.</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-02_settings.png" width="416" height="465" alt="Settings." /></p>
<p>Script debugging in IE needs be enabled, which requires us to disable the first option out of the three. If you also want to debug scripts in other contexts (such as Outlook) then disable the second option. Enable the third option if you&#8217;d like the JavaScript error dialog to pop up automatically instead of being displayed as a small icon in the status bar.</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-03_error-debug.png" width="226" height="160" alt="Error Debugging." /></p>
<p>After changing those settings and restarting IE, we&#8217;re ready to start debugging. All of the following examples show Visual Studio 2005, but the same applied to 2008. You can also use the free <a href="http://www.microsoft.com/express/download/default.aspx#webInstall">Web Developer Express Edition</a> if you don&#8217;t own a full copy of Visual Studio. Instead of IE prompting you to open the debugger, as it does in the examples below, you&#8217;ll first need to create a project and then start the debugger yourself. From that point on everything is the same.</p>
<h3>Basic debugging</h3>
<p>Let&#8217;s start with a simple example. The code below tries to call a function that doesn&#8217;t exist:</p>
<pre>
&lt;script type="text/JavaScript"&gt;
	functionDoesNotExist();
&lt;/script&gt;
</pre>
<p>Now when we load that up into the browser instead of the tiny icon in the status bar IE will prompt us to open a debugger.
  </p>
</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-04_select-debugger.png" width="403" height="438" alt="Select Debugger." /> </p>
<p>Selecting Visual Studio and clicking the yes button will open Visual Studio and highlight the code that is the cause of the problem.</p>
<p><a href="http://images.sixrevisions.com/2009/05/14-13_visual-studio-debugger_large.png"><img src="http://images.sixrevisions.com/2009/05/14-05_visual-studio-debugger.png" width="550" height="443" alt="Visual Studio." /></a></p>
<p>For relatively simple errors, such as the one in the example above, just seeing the actual cause of the error highlighted is probably enough for us to work out what has gone wrong, and how to fix it. In more complex cases, however, we&#8217;ll need more information. This where the Visual Studio debugging features come in really handy.</p>
<p>In the code below we have a function, performAction, which takes a function as an argument and calls that function once it&#8217;s done. You&#8217;ll commonly see this sort of thing in JavaScript with asynchronous functions such as <a href="https://developer.mozilla.org/en/DOM/window.setTimeout">setTimeout</a> and jQuery&#8217;s <a href="http://docs.jquery.com/Ajax/jQuery.get">Get</a>. There is a problem with the code below though: We&#8217;re accidentally passing in a string to performAction rather than a function.</p>
<pre>
&lt;script type="text/JavaScript"&gt;
  /**
   * Perform an imaginary action, and then
   * call the callback function once we're done
   */
  function performAction(callback) {
  // Perform an action here
  // ...
  // We're done, call the callback
     callback();
}
  // Call performAction with an anonymous
  // callback function which contains an error
  var myFunc = "this is a string, not a function!";
  performAction(myFunc);
&lt;/script&gt;
</pre>
<p>If we load up the code in IE and then debug it in Visual Studio as we have before we&#8217;ll see that the code &#8220;callback();&#8221; is highlighted, and is therefore the cause of problem. It won&#8217;t be obvious why this line is causing the problem though, not unless we know what the value of callback is. If callback was actually a function then there wouldn&#8217;t be a problem at all. The problem has only arisen because we accidentally passed in a string. This is where the &#8220;locals&#8221; window comes in handy. It lists all local variables along with their value and type. To display this window go to the <em>Debug</em> menu, then <em>Windows</em>, and then select <em>Locals</em>.</p>
<p><a href="http://images.sixrevisions.com/2009/05/14-14_debug-window-menu_large.png"><img src="http://images.sixrevisions.com/2009/05/14-06_debug-window-menu.png" width="550" height="442" alt="Debug Window." /></a></p>
<p>With the locals window displayed it&#8217;s clear that the problem is that callback is a string, rather than a function. The locals window doesn&#8217;t just support basic types such as integers and strings. If you&#8217;ve got a local object you can look at all of its properties and see the value and type of each of them, as we&#8217;ll see in the next example.</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-07_local-window.png" width="458" height="288" alt="Local Window." /></p>
<h3>The &#8216;debugger&#8217; keyword</h3>
<p>The &#8216;debugger&#8217; keyword, also supported by the Firefox JavaScript debugger <a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a>, can really help us to track down problems. Below is a slightly modified version of the previous example, where this time the callback function is passed an object that should include a status and message property. The message property has been misspelled though:</p>
<pre>
&lt;script type="text/JavaScript"&gt;
  /**
   * Perform an imaginary action, and then
   * call the callback function once we're done
   */
  function performAction(callback) {
    // Perform an action here
    // ...

    // We're done, call the callback
    callback({success: true, mesage: 'The action was performed!'});
  }

  // Call performAction with an anonymous
  // callback function which contains an error
  performAction(function(response) {
    alert(response.message);
  });
&lt;/script&gt;
</pre>
<p>Because &#8216;message&#8217; has been misspelt as &#8216;mesage&#8217; in the performAction function when we run this code in IE we&#8217;ll see a popup alert with the message &#8220;undefined&#8221;, rather than the actual message we were hoping to see.</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-08_alert-undefined.png" width="205" height="130" alt="Alert function." /></p>
<p>In a large project it can be difficult to track down why a property we expect to exist is undefined. Instead of trawling through lots of code we can simply add the line &#8220;debugger;&#8221; above the alert statement. IE will then automatically prompt us to debug the code in Visual Studio when it hits that line. From the locals window we can see that the &#8216;message&#8217; property has been misspelt.</p>
<p><a href="http://images.sixrevisions.com/2009/05/14-15_debugger-statement_large.png"><img src="http://images.sixrevisions.com/2009/05/14-09_debugger-statement.png" width="550" height="444" alt="Debugger statement." /></a></p>
<p>Using the call stack window, which can be accessed in the same way we accessed the locals window, shown at the bottom right of the above screenshot we can work out exactly where this problem occurred. If we double click on the &#8216;performAction&#8217; line, the previous statement in the call stack, we&#8217;ll see the source of the error.</p>
<p><a href="http://images.sixrevisions.com/2009/05/14-16_callstack_large.png"><img src="http://images.sixrevisions.com/2009/05/14-10_callstack.png" width="550" height="442" alt="Call stack." /></a></p>
<p>While debugger statements can be a useful tool in helping you track down problems you should be careful not to leave them in your production code!</p>
<h3>More advanced debugging</h3>
<p>So far we&#8217;ve covered some basic examples, such as calling non-existent functions and undefined properties. Using the locals and call stack windows it was relatively straight forward to track these issues down. There are times when the techniques we&#8217;ve discussed so far can&#8217;t help though. We can&#8217;t see what global variables exist or what value they have with the locals window, for example, and the call stack doesn&#8217;t always handle remotely loaded or dynamically executed code very well.</em></p>
<p>For these situations we must turn to the immediate window. It is by far the most powerful debugging tool that Visual Studio has to offer, allowing us to evaluate JavaScript expressions on the fly.</p>
<p>The immediate window can be accessed in the same way that we accessed the other windows. Clicking inside the window will give it focus. We can then type JavaScript statements directly into the window and see the result. For example, type &#8220;window&#8221; followed by enter and you&#8217;ll get a print out of everything in the global scope.</p>
<p><a href="../wp-content/themes/"><img src="http://images.sixrevisions.com/2009/05/14-11_immediate-window-output.png" width="550" height="395" alt="Immediate Window." /></a></p>
<p>When combined with the JavaScript <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions_and_function_scope/Arguments">arguments</a> variable we can look in detail at all the current function arguments and the calling function. While the code in the next example isn&#8217;t something you&#8217;re likely to see in a real project, it does help to demonstrate techniques that can be extremely useful.</p>
<pre>
&lt;script type="text/JavaScript"&gt;
  /**
   * This function takes a variable number of arguments.
   */
  function performAction() {
    // We're just interested in the immediate
    // window, start the debugger
    debugger;
  }

  // Call performAction with 4 different arguments, each of a different type
  performAction('argument 1', 2, {argument: 3}, function() { return 4; });
&lt;/script&gt;
</pre>
<p>We&#8217;ll load this up into IE and then go straight to the immediate window once we&#8217;ve opened up the debugger. If we type &#8220;arguments&#8221; followed by enter we&#8217;ll see the following information displayed:</p>
<pre>
arguments
{...}
    [0]: "argument 1"
    [1]: 2
    [2]: {...}
    caller: null
    length: 4
</pre>
<p>The &#8220;{&#8230;}&#8221; tells us that arguments is an object. We also see this next to [2], so we know that the third argument (in array position 2) is an object. We can see what properties this object has by simply typing its name into the window:</p>
<pre>
arguments[2]
{...}
    argument: 3
</pre>
<p>The fourth argument wasn&#8217;t listed in the original output because it&#8217;s a function. We know it exists though because the length property tells us that there are 4 arguments. We can also confirm it is there using typeof:</p>
<pre>
typeof arguments[3]
"function"
</pre>
<p>Unfortunately the immediate window isn&#8217;t quite so helpful with functions as it is objects, and if we type in the name of the function we just see &#8220;{&#8230;}&#8221; rather than any details of the function itself. Fortunately there is a handy workaround. If we type &#8220;alert(arguments[3]);&#8221; then the function code will be displayed in an alert dialog:</p>
<p><img src="http://images.sixrevisions.com/2009/05/14-12_alert-function.png" width="206" height="128" alt="Alert function." /></p>
<p>Hopefully these examples have conveyed just how powerful the immediate window is.</p>
<h3>Summary</h3>
<p>With the help of Visual Studio it is possible to transform IE6 from obscure error messages into an effective debugger. By using the local and call stack windows we can quickly and easily track down the majority of problems. The debugger statement allows us to automatically jump into the debugger at any point in our code. Should we come up again a more complex where the other tools can&#8217;t help us then we can always turn to the immediate window, which allows us to execute arbitrary JavaScript to inspect the current environment.</p>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/ben_dowling_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Ben Dowling</strong> is a passionate software developer who specializes in web and mobile application development. He currently works for <a href="http://www.mendeley.com">Mendeley</a> in London, UK, and regularly blogs about development at <a href="http://www.coderholic.com">Coderholic</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
	</channel>
</rss>
