<?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>ViralPatel.net &#187; JQuery</title>
	<atom:link href="http://viralpatel.net/blogs/category/javascript/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://viralpatel.net/blogs</link>
	<description>Tutorials, Java, J2EE, Struts, AJAX, JavaScript, CSS, Web 2.0, MySQL, Articles</description>
	<lastBuildDate>Wed, 10 Mar 2010 12:02:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Understanding jQuery animate() function</title>
		<link>http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html</link>
		<comments>http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html#comments</comments>
		<pubDate>Tue, 09 Mar 2010 13:08:15 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[jQuery Effects]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2045</guid>
		<description><![CDATA[jQuery animate() function is very powerful API to manipulate html elements and add animation functionality. The use of animate function is very simple. First lets check the syntax of this function.
.animate( properties, [ duration ], [ easing ], [ callback ] )

properties: A map of CSS properties that the animation will move toward.
duration: A string [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/jquery-logo.png" alt="" title="jquery-logo" width="236" height="85" class="alignright size-full wp-image-1108" />jQuery animate() function is very powerful API to manipulate html elements and add animation functionality. The use of animate function is very simple. First lets check the syntax of this function.</p>
<p><strong>.animate( properties, [ duration ], [ easing ], [ callback ] )</strong></p>
<ul>
<li>properties: A map of CSS properties that the animation will move toward.</li>
<li>duration: A string or number determining how long the animation will run.</li>
<li>easing: A string indicating which easing function to use for the transition.</li>
<li>callback: A function to call once the animation is complete.</li>
</ul>
<p><strong>.animate( properties, options )</strong></p>
<ul>
<li>properties: A map of CSS properties that the animation will move toward.</li>
<li>options: A map of additional options to pass to the method. Supported keys:
<ul>
<li>duration: A string or number determining how long the animation will run.</li>
<li>easing: A string indicating which easing function to use for the transition.</li>
<li>complete: A function to call once the animation is complete.</li>
<li>step: A function to be called after each step of the animation.</li>
<li>queue: A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately.</li>
<li>specialEasing: A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions (added 1.4).</li>
</ul>
</li>
</ul>
<p>Lets learn the animate() function with set of examples.</p>
<p>First include the jQuery javascript library in your html file. Add following in your html &lt;HEAD&gt; tag:</p>
<pre class="brush: xml;">
&lt;SCRIPT type=&quot;text/javascript&quot;
		src=&quot;http://code.jquery.com/jquery-latest.js&quot;&gt;&lt;/SCRIPT&gt;
</pre>
<p>For all the demos, we will use a sample DIV tag for animating. Following is the div code and its stylesheet.</p>
<pre class="brush: xml;">
&lt;style type=&quot;text/css&quot;&gt;
#content {
	background-color:#ffaa00;
	width:300px;
	height:30px;
	padding:3px;
}
&lt;/style&gt;
&lt;input type=&quot;button&quot; id=&quot;animate&quot; value=&quot;Animate&quot;/&gt;
&lt;div id=&quot;content&quot;&gt;Animate Height&lt;/div&gt;
</pre>
<h2>Animate height/width</h2>
<p>Animating height and width in jQuery is very easy. Lets assume you have a DIV that you want to animate i.e. increase the height.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;height&quot;: &quot;80px&quot;},
			&quot;fast&quot;);
});
</pre>
<p><strong>Demo 1:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-height.html" width="100%" height="150px" frameborder="0"></iframe></p>
<p>Also following will be the code to animate Width of the element.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;width&quot;: &quot;350px&quot;},
			&quot;fast&quot;);
});
</pre>
<p><strong>Demo 2:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-width.html" width="100%" height="120px" frameborder="0"></iframe></p>
<h2>Animate opacity</h2>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;opacity&quot;: &quot;0.15&quot;},
			&quot;slow&quot;);
});
</pre>
<p><strong>Demo 3:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-opacity.html" width="100%" height="120px" frameborder="0"></iframe></p>
<h2>Moving elements using animate()</h2>
<pre class="brush: xml;">
&lt;STYLE&gt;
#content {
	background-color:#6688ff;
	position:absolute;
	width:100px;
	height:100px;
	padding:3px;
	margin-top:5px;
	left: 100px;
}
&lt;/STYLE&gt;
&lt;input type=&quot;button&quot; id=&quot;left&quot; value=&quot;Left&quot;/&gt;
&lt;input type=&quot;button&quot; id=&quot;right&quot; value=&quot;Right&quot;/&gt;
&lt;div id=&quot;content&quot;&gt;Move&lt;/div&gt;
</pre>
<pre class="brush: jscript;">
$(&quot;#right&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;left&quot;: &quot;+=50px&quot;},
			&quot;slow&quot;);
});
$(&quot;#left&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;left&quot;: &quot;-=50px&quot;},
			&quot;slow&quot;);
});
</pre>
<p><strong>Demo 4:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-move.html" width="100%" height="150px" frameborder="0"></iframe></p>
<h2>Callback Function</h2>
<p>Callback functions are very useful to perform certain activity when the animation is completed. Also note here when multiple elements are mapped with the animation and we have specified a callback function. Then the callback will get called for each of the element.</p>
<p>Let us see an example where we use callback function to display a message when animation is completed. </p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;height&quot;: &quot;100px&quot;, &quot;width&quot;: &quot;250px&quot;},
			&quot;slow&quot;, function(){
				$(this).html(&quot;Animation Completed&quot;);
			});
});</pre>
<p><strong>Demo 5:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-callback.html" width="100%" height="150px" frameborder="0"></iframe></p>
<h2>Combine multiple animations</h2>
<p>You may want to combine multiple animations. Following are few demos will help you understanding this.</p>
<p><strong>Example 1</strong>: Animate both height and width at same time.<br />
This example is pretty straight forward. You can animate both height and width at same time by specifying it in animate function. For example: In below code we specified height and width value in animate function.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;).animate(
			{&quot;height&quot;: &quot;100px&quot;, &quot;width&quot;: &quot;250px&quot;},
			&quot;slow&quot;, );
});</pre>
<p><strong>Example 2</strong>: Queuing the animations.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;)
		.animate({&quot;height&quot;: &quot;100px&quot;}, 500)
		.animate({&quot;width&quot;: &quot;250px&quot;}, 500);
});
</pre>
<p><strong>Demo 6:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-queue.html" width="100%" height="150px" frameborder="0"></iframe></p>
<h2>Queuing of Events</h2>
<p>In above demo (Demo 6) we saw that when we queued up the events with multiple .animate() method call, the animation is actually queued up. i.e. it completes the first animation and then proceed with next. Let see an example were we use <code>queue</code> parameter to disable queuing. In following example we have set parameter <code>queue</code> to <code>false</code>. The code is exactly same as demo 6, only change we added is queue = false. Also note that queue parameter is added with second argument.</p>
<pre class="brush: jscript;">
$(&quot;#animate&quot;).click(function() {
	$(&quot;#content&quot;)
		.animate({&quot;height&quot;: &quot;100px&quot;}, {&quot;queue&quot;: false, &quot;duration&quot;: 500})
		.animate({&quot;width&quot;: &quot;250px&quot;}, 500);
});
</pre>
<p><strong>Demo 7:</strong><br />
<iframe src="http://viralpatel.net/blogs/demo/jquery/animate-demo/animate-queue-false.html" width="100%" height="150px" frameborder="0"></iframe></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" title="Create Simplest Accordion Menu using jQuery">Create Simplest Accordion Menu using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html" title="20 Top jQuery tips &#038; tricks for jQuery programmers">20 Top jQuery tips &#038; tricks for jQuery programmers</a></li><li><a href="http://viralpatel.net/blogs/2009/07/delete-row-html-table-clicking-using-jquery.html" title="Delete Row from HTML Table by clicking it using jQuery">Delete Row from HTML Table by clicking it using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/03/how-to-apply-html-user-interface-effects-using-jquery.html" title="How to apply HTML User Interface Effects using jQuery.">How to apply HTML User Interface Effects using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" title="jQuery Live Event">jQuery Live Event</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html&amp;title=Understanding jQuery animate() function" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>oEmbed: An Open Format Every Developer Should Know About</title>
		<link>http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html</link>
		<comments>http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html#comments</comments>
		<pubDate>Tue, 26 Jan 2010 09:24:36 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[oembed]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2000</guid>
		<description><![CDATA[
Most of the internet users spend their online time in creating and sharing content on internet. Sharing has became one of the most popular activity of internet users. This is attributed to formats like RSS and services like Twitter, Facebook etc. that allows user to share content with each other. 
oEmbed addresses the important task [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2010/01/oembed-all-service.png" alt="oembed-all-service" title="oembed-all-service" width="352" height="180" class="aligncenter size-full wp-image-2002" /><br />
Most of the internet users spend their online time in creating and sharing content on internet. Sharing has became one of the most popular activity of internet users. This is attributed to formats like RSS and services like Twitter, Facebook etc. that allows user to share content with each other. </p>
<p>oEmbed addresses the important task of sharing and embedding information anywhere on internet. It allows developers to build applications that can easily access data from vast number of websites like youtube, flickr, google video, wordpress, wikipedia and many many more.</p>
<p>So what&#8217;s oEmbed? Well if you go by the definition on oEmbed&#8217;s <a rel="nfollow" target="_blank" href="http://www.oembed.com/">official website</a>:</p>
<blockquote><p>oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.
</p></blockquote>
<p>The best example of oEmbed can be Facebook&#8217;s status update feature. When you paste a youtube movie link in Facebook&#8217;s status bar, it automatically identify the link content as youtube movie and embed it in the status. Similarly you can paste any kind of content link: Flickr, Wikipedia etc. </p>
<p><img src="http://img.viralpatel.net/2010/01/facebook-oembed.png" alt="facebook-oembed" title="facebook-oembed" width="564" height="364" class="aligncenter size-full wp-image-2001" /></p>
<h2>Basics of oEmbed</h2>
<p>In this document I will use two terms very often, <strong>consumer</strong> and <strong>provider</strong>. Consumer is the client who wants to convert a link into embedded content. And Provider is one who get the request and send the oembed response. For example, if you paste a youtube URL in Facebook&#8217;s status update, Facebook will be the consumer and Youtube will be the provider. </p>
<p>A consumer who wants to convert a link into content will make an HTTP request like:</p>
<pre class="brush: xml;">
http://www.flickr.com/services/oembed/?url=http%3A//www.flickr.com/photos/bees/2341623661/
</pre>
<p>and the provider, in this case Flickr will send response in JSON format:</p>
<pre class="brush: xml;">
{
	&quot;version&quot;: &quot;1.0&quot;,
	&quot;type&quot;: &quot;photo&quot;,
	&quot;width&quot;: 240,
	&quot;height&quot;: 160,
	&quot;title&quot;: &quot;ZB8T0193&quot;,
	&quot;url&quot;: &quot;http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg&quot;,
	&quot;author_name&quot;: &quot;Bees&quot;,
	&quot;author_url&quot;: &quot;http://www.flickr.com/photos/bees/&quot;,
	&quot;provider_name&quot;: &quot;Flickr&quot;,
	&quot;provider_url&quot;: &quot;http://www.flickr.com/&quot;
}
</pre>
<p><strong>Youtube example:</strong><br />
Request URL:</p>
<pre class="brush: xml;">
http://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3DM3r2XDceM6A&amp;format=json
</pre>
<p>Response:</p>
<pre class="brush: xml;">
{
	&quot;version&quot;: &quot;1.0&quot;,
	&quot;type&quot;: &quot;video&quot;,
	&quot;provider_name&quot;: &quot;YouTube&quot;,
	&quot;provider_url&quot;: &quot;http://youtube.com/&quot;,
	&quot;width&quot;: 425,
	&quot;height&quot;: 344,
	&quot;title&quot;: &quot;Amazing Nintendo Facts&quot;,
	&quot;author_name&quot;: &quot;ZackScott&quot;,
	&quot;author_url&quot;: &quot;http://www.youtube.com/user/ZackScott&quot;,
	&quot;html&quot;:
		&quot;&lt;object width=\&quot;425\&quot; height=\&quot;344\&quot;&gt;
			&lt;param name=\&quot;movie\&quot; value=\&quot;http://www.youtube.com/v/M3r2XDceM6A&amp;fs=1\&quot;&gt;&lt;/param&gt;
			&lt;param name=\&quot;allowFullScreen\&quot; value=\&quot;true\&quot;&gt;&lt;/param&gt;
			&lt;param name=\&quot;allowscriptaccess\&quot; value=\&quot;always\&quot;&gt;&lt;/param&gt;
			&lt;embed src=\&quot;http://www.youtube.com/v/M3r2XDceM6A&amp;fs=1\&quot;
				type=\&quot;application/x-shockwave-flash\&quot; width=\&quot;425\&quot; height=\&quot;344\&quot;
				allowscriptaccess=\&quot;always\&quot; allowfullscreen=\&quot;true\&quot;&gt;&lt;/embed&gt;
		&lt;/object&gt;&quot;,
}</pre>
<p>Once the consumer get the response, all it has to do is to utilize the content and embed it in the page.</p>
<h3>Request Format</h3>
<p>The consumer who is requesting for the embed content must follow some basic rules while sending request. Requests sent to the API must be HTTP GET requests, with all arguments sent as query parameters. All arguments must be urlencoded.<br />
Following are the request parameters:</p>
<ul>
<li><strong>url</strong> (required): This is the URL for which embedded content is requested</li>
<li><strong>maxwidth</strong> (optional): An optional parameter for maxwidth can be passed. Some of the content provider who support this param will send the response content accordingly. For example, Flickr may set the maxwidth of image.</li>
<li><strong>maxheight</strong> (optional): Similar to maxwidth, maxheight is an optional param. </li>
<li><strong>format</strong> (optional): By default the content provider&#8217;s response is in JSON. But consumer may want the response in other formats like XML. This parameter will determine is response format</li>
</ul>
<h3>Response Format</h3>
<p>The provider who sends the response back to consumer may send it with following parameters.</p>
<ul>
<li><strong>type</strong> (required): The resource type. Valid values, along with value-specific parameters, are described below.</li>
<li><strong>version</strong> (required): The oEmbed version number. This must be 1.0.</li>
<li><strong>title</strong> (optional): A text title, describing the resource.</li>
<li><strong>author_name</strong> (optional): The name of the author/owner of the resource.</li>
<li><strong>author_url</strong> (optional): A URL for the author/owner of the resource.</li>
<li><strong>provider_name</strong> (optional): The name of the resource provider.</li>
<li><strong>provider_url</strong> (optional): The url of the resource provider.</li>
<li><strong>cache_age</strong> (optional): The suggested cache lifetime for this resource, in seconds. Consumers may choose to use this value or not.</li>
<li><strong>thumbnail_url</strong> (optional): A URL to a thumbnail image representing the resource. The thumbnail must respect any maxwidth and maxheight parameters. If this paramater is present, thumbnail_width and thumbnail_height must also be present.</li>
<li><strong>thumbnail_width</strong> (optional): The width of the optional thumbnail. If this paramater is present, thumbnail_url and thumbnail_height must also be present.</li>
<li><strong>thumbnail_height</strong> (optional): The height of the optional thumbnail. If this paramater is present, thumbnail_url and thumbnail_width must also be present.</li>
</ul>
<p>The provider may wants to add more attributes to the response. </p>
<h2>Letting People Know You Support oEmbed</h2>
<p>The oEmbed providers can make their service discoverable by adding following element in HEAD for the HTML document.</p>
<pre class="brush: xml;">
&lt;link rel=&quot;alternate&quot; type=&quot;application/json+oembed&quot;
	href=&quot;http://flickr.com/services/oembed?url=http%3A//flickr.com/photos/bees/2362225867/&amp;format=json&quot;
	title=&quot;Bacon Lollys oEmbed Profile&quot; /&gt;
&lt;link rel=&quot;alternate&quot; type=&quot;text/xml+oembed&quot;
	href=&quot;http://flickr.com/services/oembed?url=http%3A//flickr.com/photos/bees/2362225867/&amp;format=xml&quot;
	title=&quot;Bacon Lollys oEmbed Profile&quot; /&gt;
</pre>
<p>The URLs contained within the href attribute should be the full oEmebed endpoint plus URL and any needed format parameter. No other request parameters should be included in this URL.</p>
<p>The type attribute must contain either application/json+oembed for JSON responses, or text/xml+oembed for XML.</p>
<h2>oEmbed Demo with jQuery</h2>
<p>Integrating oEmbed support in your application using jQuery is very easy using <a rel="nofollow" target="_blank" href="http://code.google.com/p/jquery-oembed/">jQuery oEmbed plugin</a>. Following is the source code the of demo.<br />
<b>The HTML Code</b></p>
<pre class="brush: xml;">
Content URL:
&lt;input type=&quot;text&quot; id=&quot;update&quot;/&gt;&lt;button id=&quot;btn&quot;&gt;Get&lt;/button&gt;
&lt;div id=&quot;embed&quot;&gt;&lt;/div&gt;
</pre>
<p><b>The jQuery Code</b></p>
<pre class="brush: jscript;">
$(function(){
	$('#btn').click(function() {
		$(&quot;#embed&quot;).oembed($('#update').val());
	});
});
</pre>
<p>Don&#8217;t forget to include jquery library and jquery oembed javascript in the demo.<br />
<b>The Demo</b><br />
Enter any oEmbed supporting URL (Youtube video link or Flickr link <strong>http://www.flickr.com/photos/stuckincustoms/2035748576/</strong>) in below textbox and press Get.<br />
<iframe src="http://viralpatel.net/blogs/demo/oembed/demo.html" width="100%" height="300px"></iframe><br />
(<a target="_blank" href="http://viralpatel.net/blogs/demo/oembed/demo.html">demo link</a>)</p>
<h3>oEmbed in PHP</h3>
<p>There is a small PHP library that can be used to integrate oEmbed support in PHP. <a rel="nofollow" target="_blank" href="http://code.google.com/p/php-oembed/">oEmbed-PHP</a> is a library that provides OEmbed compatible interface for javascript and PHP clients to consume. It can deal with OEmbed providers by acting as a proxy, and it has a plugin system where you can add your own embed-providers.<br />
Import this small PHP library and directly use it in your application.</p>
<pre class="brush: php;">
  $manager = ProviderManager::getInstance();
  $obj=$manager-&gt;provide(&quot;http://www.youtube.com/watch? v=EQqJSAOOmGI&quot;,&quot;object&quot;);
  $html=$obj-&gt;renderClass();
</pre>
<h2>oEmbed for other languages</h2>
<p><b>Perl</b><br />
Web-oEmbed (<a rel="nofollow" target="_blank" href="http://search.cpan.org/~miyagawa/Web-oEmbed/">http://search.cpan.org/~miyagawa/Web-oEmbed/</a>)</p>
<p><b>Ruby</b><br />
oembed_links (<a rel="nofollow" target="_blank" href="http://github.com/netshade/oembed_links">http://github.com/netshade/oembed_links</a>)</p>
<p><b>Python</b><br />
Python oEmbed (<a rel="nofollow" target="_blank" href="http://code.google.com/p/python-oembed/">http://code.google.com/p/python-oembed/</a>)</p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/09/gartners-hype-cycle-special-report-2009.html" title=" Gartner&#8217;s Hype Cycle Special Report for 2009"> Gartner&#8217;s Hype Cycle Special Report for 2009</a></li><li><a href="http://viralpatel.net/blogs/2009/07/youtube-experimenting-3d-videos.html" title="YouTube Experimenting with 3D videos!">YouTube Experimenting with 3D videos!</a></li><li><a href="http://viralpatel.net/blogs/2009/05/gravatar-manage-your-user-avatars-for-free.html" title="Gravatar: Manage your user avatars for free">Gravatar: Manage your user avatars for free</a></li><li><a href="http://viralpatel.net/blogs/2009/05/web-30-is-around-the-corner.html" title="Web 3.0 is around the corner !">Web 3.0 is around the corner !</a></li><li><a href="http://viralpatel.net/blogs/2009/05/capture-website-screenshot-screenshot-capture-utilities.html" title="Capture Website Screenshot with screenshot capture utilities">Capture Website Screenshot with screenshot capture utilities</a></li><li><a href="http://viralpatel.net/blogs/2009/03/chrome-experiment-googles-new-site-showcase-chrome-javascript.html" title="Chrome Experiment: Google&#8217;s new site to showcase Chrome and JavaScript">Chrome Experiment: Google&#8217;s new site to showcase Chrome and JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/02/google-maps-and-twitter-mashup-show-uk-snowfall-google-map-twitter-mashup.html" title="Google Maps and Twitter mashup show UK snowfall !!">Google Maps and Twitter mashup show UK snowfall !!</a></li><li><a href="http://viralpatel.net/blogs/2009/01/introduction-to-google-maps.html" title="Introduction to Google Maps.">Introduction to Google Maps.</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html&amp;title=oEmbed: An Open Format Every Developer Should Know About&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html&amp;title=oEmbed: An Open Format Every Developer Should Know About" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html&amp;title=oEmbed: An Open Format Every Developer Should Know About" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html&amp;title=oEmbed: An Open Format Every Developer Should Know About" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Resizable and Draggable Tutorial with Example</title>
		<link>http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html</link>
		<comments>http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html#comments</comments>
		<pubDate>Mon, 25 Jan 2010 09:48:15 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[jquery drag drop]]></category>
		<category><![CDATA[jquery resize]]></category>
		<category><![CDATA[jquery resizeable]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2006</guid>
		<description><![CDATA[Have you ever tried doing some animation using plain Javascript or moving DIVs here and there or resizing them?! Well, you know then how much pain it is as not only you have to tackle the difficult part of animation but also making it cross browser compatible.
Well you probably know why I am stretching up [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/05/jquery-thumb.jpg" alt="" title="jquery-thumb" width="250" height="178" class="alignright size-full wp-image-1244" />Have you ever tried doing some animation using plain Javascript or moving DIVs here and there or resizing them?! Well, you know then how much pain it is as not only you have to tackle the difficult part of animation but also making it cross browser compatible.</p>
<p>Well you probably know why I am stretching up so hard is just to tell you how easy it is to use jQuery and do some really fantastic things without even bothering of knowing how it is done internally. jQuery comes with really useful UI library that can be incorporated to do such tricks.</p>
<p>In this small note, I will show you how to do Resizing and Dragging of a DIV using jQuery UI. I will show you the demo of a DIV, which can be resized by pulling up the edges and also dragged here and there.</p>
<h2>Step 1: Setting up jQuery UI and CSS</h2>
<p>We need to install jQuery UI library first in order to do resizing/dragging. Add following lines in your HEAD of html document.</p>
<pre class="brush: xml;">
&lt;script type=&quot;text/javascript&quot;
	src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
	src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot;
	href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css&quot;/&gt;
</pre>
<p>Note that we have imported jquery and jquery-ui library. Also, to use Resizable we must import jquery-ui.css file. This stylesheet will be used by resizable to add resize corner and other internal styles.</p>
<h2>Step 2: Write jQuery to Resize and Drag</h2>
<p>For the demo we will define a small DIV which we will make resizable and draggable.</p>
<pre class="brush: xml;">
&lt;div id=&quot;resizeDiv&quot;&gt;&lt;/div&gt;
</pre>
<p>Now just add following jQuery code in your document.</p>
<pre class="brush: jscript;">
$('#resizeDiv')
	.draggable()
	.resizable();
</pre>
<p>The beauty of jQuery is that we can simply chain the function calling. First we called .draggable() function that makes the DIV draggable and then we called resizable().<br />
You may want to define callback functions on start/stop/resize events. To do so we simply define:</p>
<pre class="brush: jscript;">
$('#resizeDiv')
	.resizable({
		start: function(e, ui) {
			alert('resizing started');
		},
		resize: function(e, ui) {

		},
		stop: function(e, ui) {
			alert('resizing stopped');
		}
	});
</pre>
<p>Note that the callback function gets two arguments. First is <strong>event</strong> object and next is <strong>ui</strong>.<br />
The ui object has the following fields:</p>
<ul>
<li><strong>ui.helper</strong> &#8211; a jQuery object containing the helper element</li>
<li><strong>ui.originalPosition</strong> &#8211; {top, left} before resizing started</li>
<li><strong>ui.originalSize</strong> &#8211; {width, height} before resizing started</li>
<li><strong>ui.position</strong> &#8211; {top, left} current position</li>
<li><strong>ui.size</strong> &#8211; {width, height} current size</li>
</ul>
<p>For more information about jQuery Draggable (Drag and Drop) read this article.<br />
<a target="_blank" href="http://viralpatel.net/blogs/2009/05/implement-drag-and-drop-example-jquery-javascript-html.html">jQuery Draggable (Drag and Drop)</a></p>
<h2>Online Demo</h2>
<p>Following is the online demo of jQuery Resizable and Draggable.<br />
<iframe src="http://viralpatel.net/blogs/demo/jquery-resize-drag/demo.html" width="100%" height="300px"></iframe><br />
(<a target="_blank" href="http://viralpatel.net/blogs/demo/jquery-resize-drag/"><strong>Demo Link</strong></a>)</p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/05/implement-drag-and-drop-example-jquery-javascript-html.html" title="Drag and Drop Example using jQuery JavaScript in HTML">Drag and Drop Example using jQuery JavaScript in HTML</a></li><li><a href="http://viralpatel.net/blogs/2009/01/fadein-fadeout-fade-out-effect-in-html-text-div-using-jquery.html" title="FadeIn FadeOut html text div effect using jQuery.">FadeIn FadeOut html text div effect using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2008/12/creating-orkut-style-status-update-div-textbox-using-jquery.html" title="Creating orkut style status update div-textbox using jQuery.">Creating orkut style status update div-textbox using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" title="Understanding jQuery animate() function">Understanding jQuery animate() function</a></li><li><a href="http://viralpatel.net/blogs/2010/01/javascript-array-remove-element-js-array-delete-element.html" title="JavaScript Array Remove an Element ">JavaScript Array Remove an Element </a></li><li><a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" title="jQuery Live Event">jQuery Live Event</a></li><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" title="Create Simplest Accordion Menu using jQuery">Create Simplest Accordion Menu using jQuery</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html&amp;title=jQuery Resizable and Draggable Tutorial with Example&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html&amp;title=jQuery Resizable and Draggable Tutorial with Example" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html&amp;title=jQuery Resizable and Draggable Tutorial with Example" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html&amp;title=jQuery Resizable and Draggable Tutorial with Example" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery Live Event</title>
		<link>http://viralpatel.net/blogs/2009/12/jquery-live-events.html</link>
		<comments>http://viralpatel.net/blogs/2009/12/jquery-live-events.html#comments</comments>
		<pubDate>Mon, 14 Dec 2009 09:25:31 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQuery Events]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1922</guid>
		<description><![CDATA[I love jQuery. I have expressed my love for jQuery here, here and here and still I feel so much for it. Also check out the 20 jQuery Tips &#038; Tricks Tutorial.
Let us see a wonderful function available in jQuery which many of us don&#8217;t know. Most common use of jQuery is to attach an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/12/jquery-live-function.png" alt="jquery-live-function" title="jquery-live-function" width="257" height="175" class="alignleft size-full wp-image-1923" />I love jQuery. I have expressed my love for jQuery <a href="http://viralpatel.net/blogs/2009/06/textarea-resize-javascript-jquery-plugin-resize-textarea-html.html">here</a>, <a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html">here</a> and <a href="http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html">here</a> and still I feel so much for it. Also check out the <a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html">20 jQuery Tips &#038; Tricks</a> Tutorial.</p>
<p>Let us see a wonderful function available in jQuery which many of us don&#8217;t know. Most common use of jQuery is to attach an event some callback function to any element on webpage.</p>
<p>When we attach any event to element on webpage using normal functions such as mouseclick or click or mouseover, it attach the event only to current elements. If dynamically we add another element in future then this handler is not attached to those dynamic elements.</p>
<p>For example, we have a button on click of which we display an alert message. We can use <code>$('#buttonid').click()</code> to attach a handler function which can display alert message. But what if we dynamically add another button on page and we want exactly the same functionality? Well, jQuery Live Function comes to rescue for such requirements.</p>
<p>Let us see an example of normal event handling and one with Live function. In this example, we are dynamically adding list items that has hover effect. When mouse is hover on this list item, it changes the color. We will do this by both traditional way and using Live function.</p>
<h2>The HTML</h2>
<p>Following is the HTML Code for our example:</p>
<pre class="brush: xml;">
&lt;TABLE&gt;
&lt;TR valign=&quot;top&quot;&gt;
	&lt;td&gt;
	&lt;input type=&quot;button&quot; value=&quot;Click To Add (without Live)&quot; id=&quot;add&quot;/&gt;
	&lt;ul id=&quot;list&quot; class=&quot;list&quot;&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;/td&gt;
	&lt;td&gt;
	&lt;input type=&quot;button&quot; value=&quot;Click To Add (with Live)&quot; id=&quot;addLive&quot;/&gt;
	&lt;ul id=&quot;listLive&quot; class=&quot;list&quot;&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
		&lt;li&gt;&amp;nbsp;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;/td&gt;
&lt;/TR&gt;
&lt;/TABLE&gt;
</pre>
<p>The HTML will display two buttons and two list sets. One button will dynamically add list item to one list using normal click event, where as another button will use Live events to do this.</p>
<h2>The CSS</h2>
<p>We will use following CSS in our example:</p>
<pre class="brush: css;">
.list	li 	{
	list-style: none;
	background-color:#eeffaa;
	width:150px;
	margin-top:5px;
	border:1px solid #8AAC00;
}

.list li.selected {
	background-color: #ffaaee;
}
</pre>
<h2>The jQuery</h2>
<p>First we will attach an event with two buttons to dynamically add a list item. </p>
<pre class="brush: jscript;">
$('#add').click(function(){
	$('#list').append('&lt;li&gt;&amp;nbsp;&lt;/li&gt;');
});
$('#addLive').click(function(){
	$('#listLive').append('&lt;li&gt;&amp;nbsp;&lt;/li&gt;');
});
</pre>
<p>Then, we will make the first list hoverable using mouseover and mouseout event.</p>
<pre class="brush: jscript;">
$('#list&gt;li')
		.mouseover(function(){ $(this).addClass('selected'); })
		.mouseout(function(){ $(this).removeClass('selected'); });
</pre>
<p>And, then we will make the second list hoverable using <code>live()</code> event.</p>
<pre class="brush: jscript;">
$('#listLive&gt;li')
	.live('mouseover', function(){ $(this).addClass('selected');   })
	.live('mouseout',  function(){ $(this).removeClass('selected'); });
</pre>
<p>Notice the difference in above code. In first snippet we are using mouseover and mouseout functions to attach events with handlers to change the background color of list item. When we add a list item dynamically, this handler are not attached to newly created list item. And in second snippet we are using live() to attach event mouseover and mouseout.</p>
<p>This way we ensure that any dynamically added element will have the events handler attached with them.<br />
<b>jQuery 1.3 and below</b><br />
Currently jQuery 1.3 and below is not supporting events blur, focus, mouseenter, mouseleave, change, submit.<br />
But the good news is that jQuery 1.4 alpha 1 has just <a rel="nofollow" target="_new" href="http://blog.jquery.com/2009/12/04/jquery-14-alpha-1-released/">been released</a> which supports these events.</p>
<h2>Important Points</h2>
<p>Following are few important points one should note before working with Live events.</p>
<ul>
<li>When you bind a &#8220;live&#8221; event it will bind to all current and future elements on the page.</li>
<li>Live events do not bubble in the traditional manner and cannot be stopped using <code>stopPropagation</code> or <code>stopImmediatePropagation</code>.</li>
<li>Live events currently only work when used against a selector. For example, this would work: <code>$("li a").live(...)</code> but this would not: <code>$("a", someElement).live(...)</code> and neither would this: <code>$("a").parent().live(...)</code>.</li>
<li>.live doesn&#8217;t support the no-event style callback that liveQuery provides. Only event handlers can be bound with .live.</li>
<li>.live doesn&#8217;t have a &#8220;setup&#8221; or &#8220;cleanup&#8221; step, since all events are delegated rather than bound directly to an element.</li>
<li>To remove a live event you should use the <code>die()</code> method</li>
</ul>
<h2>Live Demo</h2>
<p>Following is the live demo for jQuery Live Event Example.<br />
<iframe src="http://viralpatel.net/blogs/demo/jquery-live-event-function/demo.html" height="300px" width="100%"></iframe><br />
<a target="_blank" href="http://viralpatel.net/blogs/demo/jquery-live-event-function/"><strong>Click To View Demo</strong></a><br />
<a href="http://viralpatel.net/blogs/demo/jquery-live-event-function/source.zip"><strong>Download Source Code</strong></a></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/04/tutorial-handle-browser-events-using-jquery-javascript-framework.html" title="Tutorial: Handle browser events using jQuery JavaScript framework">Tutorial: Handle browser events using jQuery JavaScript framework</a></li><li><a href="http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" title="Understanding jQuery animate() function">Understanding jQuery animate() function</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" title="Create Simplest Accordion Menu using jQuery">Create Simplest Accordion Menu using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html" title="20 Top jQuery tips &#038; tricks for jQuery programmers">20 Top jQuery tips &#038; tricks for jQuery programmers</a></li><li><a href="http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html" title="Sum HTML Textbox Values using jQuery / JavaScript">Sum HTML Textbox Values using jQuery / JavaScript</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2009/12/jquery-live-events.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2009/12/jquery-live-events.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2009/12/jquery-live-events.html&amp;title=jQuery Live Event&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2009/12/jquery-live-events.html&amp;title=jQuery Live Event" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2009/12/jquery-live-events.html&amp;title=jQuery Live Event" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2009/12/jquery-live-events.html&amp;title=jQuery Live Event" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2009/12/jquery-live-events.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Fantastic Bouncy Effect using jQuery/JavaScript</title>
		<link>http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html</link>
		<comments>http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html#comments</comments>
		<pubDate>Thu, 22 Oct 2009 09:51:45 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[jQuery Effects]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1874</guid>
		<description><![CDATA[
Let us see how can we create a Bounce Effect in HTML pages using jQuery. Bounce effect is an effect which resembles bouncing of a ball on floor or on a wall. These kind of effects dramatically improve user experience.
Related: FadeIn / FadeOut Effect jQuery 
The Goal

Our Goal will be to create a HTML page [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/10/bounce-effect-jquery.PNG" alt="bounce-effect-jquery" title="bounce-effect-jquery" width="487" height="93" class="aligncenter size-full wp-image-1876" /><br />
Let us see how can we create a Bounce Effect in HTML pages using jQuery. Bounce effect is an effect which resembles bouncing of a ball on floor or on a wall. These kind of effects dramatically improve user experience.<br />
<strong>Related:</strong> <a href="http://viralpatel.net/blogs/2009/01/fadein-fadeout-fade-out-effect-in-html-text-div-using-jquery.html" title="FadeIn / FadeOut Out Effect jQuery">FadeIn / FadeOut Effect jQuery</a> </p>
<h2>The Goal</h2>
<p><img src="http://img.viralpatel.net/2009/10/demo-jquery-bounce-all.png" alt="demo-jquery-bounce-all" title="demo-jquery-bounce-all" width="430" height="329" class="aligncenter size-full wp-image-1875" /><br />
Our Goal will be to create a HTML page that has 4 boxes (DIVs). Clicking each of these boxes will bounce them is a particular direction. We can control the direction as well as the speed of bouncing element with arguments to the method of jQuery. </p>
<h2>Step 1: The HTML Code</h2>
<p>Following will be the HTML code for our example:</p>
<pre class="brush: xml;">
&lt;table&gt;
&lt;tr&gt;
	&lt;td&gt;&lt;div id=&quot;bouncy1&quot;&gt;Click here to bounce. Direction: Up&lt;/div&gt;&lt;/td&gt;
	&lt;td&gt;&lt;div id=&quot;bouncy2&quot;&gt;Click here to bounce. Direction: Left&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;&lt;div id=&quot;bouncy3&quot;&gt;Click here to bounce. Direction: Right&lt;/div&gt;&lt;/td&gt;
	&lt;td&gt;&lt;div id=&quot;bouncy4&quot;&gt;Click here to bounce. Direction: Down&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br/&gt;
&lt;input id=&quot;bounceAll&quot; type=&quot;button&quot; value=&quot;Click to Bounce All!&quot;/&gt;
</pre>
<h2>Step 2: The Stylesheet CSS Code</h2>
<p>Just to add some color to our boxes, add following CSS code to your HTML:</p>
<pre class="brush: css;">
div {
	padding:5px;
	width:150px;
	height:100px;
	text-align:center;
}
#bouncy1 {
	background-color:#FFEE88;
}
#bouncy2 {
	background-color:#EE88FF;
}
#bouncy3 {
	background-color:#EE8888;
}
#bouncy4 {
	background-color:#88EEFF;
}
</pre>
<h2>Step 3: The jQuery/JavaScript Code</h2>
<p>Now we will give the actual bounce effect to the demo. We will use jQuery library for this. Also we need to include jQuery UI for bounce effect. For this we will include js files from google apis. Google host the jQuery UI and jQuery core files on their server. We can directly include it from there.</p>
<pre class="brush: xml;">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Also copy following code in your HTML to give final bounce effect.</p>
<pre class="brush: jscript;">
$(function(){

	//Add bounce effect on Click of the DIV
	$('#bouncy1').click(function () {
		  $(this).effect(&quot;bounce&quot;, { times:5 }, 300);
	});

	$('#bouncy2').click(function () {
		  $(this).effect(&quot;bounce&quot;, { direction:'left', times:5 }, 300);
	});

	$('#bouncy3').click(function () {
		  $(this).effect(&quot;bounce&quot;, { direction:'right', times:5 }, 300);
	});

	$('#bouncy4').click(function () {
		  $(this).effect(&quot;bounce&quot;, { direction:'down', times:5 }, 300);
	});

	//Bounce all DIVs on click of button
	$(&quot;#bounceAll&quot;).click(function(){
		$(&quot;div&quot;).click();
	});
});
</pre>
<h2>Online Demo</h2>
<p><iframe src="http://viralpatel.net/blogs/demo/jquery-bounce-effect/demo-article.html" width="100%" height="350px"></iframe></p>
<h3>
<a href="http://viralpatel.net/blogs/demo/jquery-bounce-effect/" target="_new">View Demo</a><br />
&nbsp;&nbsp;&nbsp;<br />
<a href="http://viralpatel.net/blogs/demo/jquery-bounce-effect/download.zip">Download</a><br />
</h3>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" title="Understanding jQuery animate() function">Understanding jQuery animate() function</a></li><li><a href="http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" title="Create Simplest Accordion Menu using jQuery">Create Simplest Accordion Menu using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html" title="20 Top jQuery tips &#038; tricks for jQuery programmers">20 Top jQuery tips &#038; tricks for jQuery programmers</a></li><li><a href="http://viralpatel.net/blogs/2009/07/delete-row-html-table-clicking-using-jquery.html" title="Delete Row from HTML Table by clicking it using jQuery">Delete Row from HTML Table by clicking it using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/03/how-to-apply-html-user-interface-effects-using-jquery.html" title="How to apply HTML User Interface Effects using jQuery.">How to apply HTML User Interface Effects using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" title="jQuery Live Event">jQuery Live Event</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html&amp;title=Fantastic Bouncy Effect using jQuery/JavaScript&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html&amp;title=Fantastic Bouncy Effect using jQuery/JavaScript" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html&amp;title=Fantastic Bouncy Effect using jQuery/JavaScript" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html&amp;title=Fantastic Bouncy Effect using jQuery/JavaScript" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Default Text Label in Textbox using JavaScript/jQuery</title>
		<link>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html</link>
		<comments>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html#comments</comments>
		<pubDate>Thu, 24 Sep 2009 12:03:46 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1800</guid>
		<description><![CDATA[
In one of my previous article about Change Form Textbox Style on Focus, we discussed about Usability and HCI issues. Slight change in web pages/input forms can increase user experience.
Nowadays, it has became a common practice to give user labels on fields that they are editing. For example, if you see Google&#8217;s custom search textbox [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/09/html-textbox-label-text.png" alt="html-textbox-label-text" title="html-textbox-label-text" width="318" height="184" class="aligncenter size-full wp-image-1801" /><br />
In one of my previous article about <a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html">Change Form Textbox Style on Focus</a>, we discussed about Usability and HCI issues. Slight change in web pages/input forms can increase user experience.</p>
<p>Nowadays, it has became a common practice to give user labels on fields that they are editing. For example, if you see Google&#8217;s custom search textbox in any website, most of them will have a Google&#8217;s Logo in background and when user clicks on Textbox, the logo disappears. Thus we can create an input form with labels in background of textboxes. When user select the textboxes, the labels disappear enabling user to edit the textbox.</p>
<p><img src="http://img.viralpatel.net/2009/09/textbox-background-text-vanish.png" alt="textbox-background-text-vanish" title="textbox-background-text-vanish" width="483" height="123" class="aligncenter size-full wp-image-1802" /></p>
<p>Let us see how can we use JavaScript/jQuery to achieve this.</p>
<h2>Step 1: The HTML</h2>
<p>We will use following simple HTML Form. Create an HTML file and Copy and paste following code.</p>
<pre class="brush: xml;">
&lt;FORM method=&quot;post&quot;&gt;
&lt;TABLE&gt;
&lt;TR&gt;
	&lt;TD&gt;Username&lt;/TD&gt;
	&lt;TD&gt;&lt;INPUT type=&quot;text&quot; value=&quot;&quot; name=&quot;username&quot; title=&quot;Enter Username&quot;/&gt;&lt;TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
	&lt;TD&gt;Age&lt;/TD&gt;
	&lt;TD&gt;&lt;INPUT type=&quot;text&quot; value=&quot;&quot; name=&quot;username&quot; title=&quot;Enter Age&quot;/&gt;&lt;TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
	&lt;TD&gt;City&lt;/TD&gt;
	&lt;TD&gt;&lt;INPUT type=&quot;text&quot; value=&quot;&quot; name=&quot;username&quot; title=&quot;Enter City&quot;/&gt;&lt;TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
	&lt;TD&gt;Comment&lt;/TD&gt;
	&lt;TD&gt;&lt;INPUT type=&quot;text&quot; value=&quot;&quot; name=&quot;username&quot; title=&quot;Enter Comment&quot;/&gt;&lt;TD&gt;
&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;/FORM&gt;
</pre>
<p>Notice that while defining each text fields, we have provided <strong>title</strong> attribute. The text that is displayed on background of textbox is taken from the Title attribute. So generally the title attribute should be like &#8220;Enter Email Address&#8221; or &#8220;Type Address&#8221;.</p>
<h2>Step 2: The CSS</h2>
<p>Copy following CSS in your HTML file. You may want to include a separate CSS file for this.</p>
<pre class="brush: css;">
.text-label {
	color: #cdcdcd;
	font-weight: bold;
}
</pre>
<p>The above CSS class is applied to the Textbox when user has not entered anything in it. Once the user starts typing in Textbox the CSS class is removed.</p>
<h2>Step 3: The JavaScript</h2>
<p>We are almost done with our implementation. Only thing left is the JavaScript code that actually add and remove css to textboxes. </p>
<pre class="brush: jscript;">
$('input[type=&quot;text&quot;]').each(function(){

	this.value = $(this).attr('title');
	$(this).addClass('text-label');

	$(this).focus(function(){
		if(this.value == $(this).attr('title')) {
			this.value = '';
			$(this).removeClass('text-label');
		}
	});

	$(this).blur(function(){
		if(this.value == '') {
			this.value = $(this).attr('title');
			$(this).addClass('text-label');
		}
	});
});
</pre>
<p>The above code is straight forward. For each textbox in the webpage, we hook handler function to events <strong>focus</strong> and <strong>blur</strong>. When Textbox is focused, check if the value is same as Title. If so, then remove the background label css and let user edit the value in textbox. And while blur event(focus lost), check the value: if user has not entered anything, set the background css again.</p>
<h2>Online Demo</h2>
<p><iframe src="http://viralpatel.net/blogs/demo/jquery-html-textbox-inline-label/demo.html" height="180px" width="100%"></iframe><br />
<a target="_new" href="http://viralpatel.net/blogs/demo/jquery-html-textbox-inline-label/"><strong>Online Demo</strong></a></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/08/if-twitter-consisted-of-100-people.html" title="If Twitter Consisted of 100 People!">If Twitter Consisted of 100 People!</a></li><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2008/11/windows-xp-with-vista.html" title="Installing Windows XP with Vista">Installing Windows XP with Vista</a></li><li><a href="http://viralpatel.net/blogs/2009/08/creating-simple-twitter-reader-client-5-minutes.html" title="Creating a simple Twitter Reader(Client) in 5 minutes!!">Creating a simple Twitter Reader(Client) in 5 minutes!!</a></li><li><a href="http://viralpatel.net/blogs/2009/04/creating-customized-search-plug-ins-for-firefox-or-ie7.html" title="Creating Customized Search Plug-ins for Firefox or IE7+">Creating Customized Search Plug-ins for Firefox or IE7+</a></li><li><a href="http://viralpatel.net/blogs/2010/01/apple-tablet-ipad-video.html" title="Finally Apple Unveiled its Tablet, The iPad (Video)">Finally Apple Unveiled its Tablet, The iPad (Video)</a></li><li><a href="http://viralpatel.net/blogs/2009/07/static-import-java-example-tutorial.html" title="Static Import in Java: New way to Import things in Java!">Static Import in Java: New way to Import things in Java!</a></li><li><a href="http://viralpatel.net/blogs/2009/07/object-oriented-programming-with-javascript.html" title="Object-Oriented programming with JavaScript">Object-Oriented programming with JavaScript</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html&amp;title=Default Text Label in Textbox using JavaScript/jQuery&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html&amp;title=Default Text Label in Textbox using JavaScript/jQuery" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html&amp;title=Default Text Label in Textbox using JavaScript/jQuery" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html&amp;title=Default Text Label in Textbox using JavaScript/jQuery" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2009/09/default-text-label-textbox-javascript-jquery.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Create Simplest Accordion Menu using jQuery</title>
		<link>http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html</link>
		<comments>http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html#comments</comments>
		<pubDate>Thu, 17 Sep 2009 16:17:03 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[accordion menu]]></category>
		<category><![CDATA[jQuery Effects]]></category>
		<category><![CDATA[jquery tips tricks]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1782</guid>
		<description><![CDATA[Let us create a simple Accordion Menu using jQuery. Accordion Menu are the menu with some animation effect. It has few top line menu items which when clicked toggles to open sub menu options. When another top level menu is selected, other open menu will automatically collapse and save useful screen area. We will use [...]]]></description>
			<content:encoded><![CDATA[<p>Let us create a simple Accordion Menu using jQuery. Accordion Menu are the menu with some animation effect. It has few top line menu items which when clicked toggles to open sub menu options. When another top level menu is selected, other open menu will automatically collapse and save useful screen area. We will use <a href="http://viralpatel.net/blogs/2009/03/how-to-apply-html-user-interface-effects-using-jquery.html">jQuery effects</a> to animate the accordion menu. jQuery provides <a href="http://viralpatel.net/blogs/2009/01/fadein-fadeout-fade-out-effect-in-html-text-div-using-jquery.html">Fade In/Fade Out effect</a>, but accordion menu looks more realistic if we use Slide In / Slide Out effect.<br />
Related: <a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html"><strong>20 jQuery Tips &#038; Tricks</strong></a><br />
<img src="http://img.viralpatel.net/2009/09/accordion-menu-example.png" alt="accordion-menu-example" title="accordion-menu-example" width="433" height="212" class="aligncenter size-full wp-image-1783" /></p>
<h2>Step 1: Create HTML for your Menu</h2>
<p>First we will create HTML for displaying out Menu. We will use List in HTML to render the menu and then we will use CSS to apply some style. Following will be our Menu code:</p>
<pre class="brush: xml;">
&lt;ul id=&quot;accordion&quot;&gt;
	&lt;li&gt;Sports&lt;/li&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Golf&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Cricket&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Football&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;li&gt;Technology&lt;/li&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Facebook&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Twitter&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;li&gt;Latest&lt;/li&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Obama&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Iran Election&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Health Care&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/ul&gt;
</pre>
<p>If you check the HTML page now it should look something like:<br />
<img src="http://img.viralpatel.net/2009/09/html-menu-list.png" alt="html-menu-list" title="html-menu-list" width="222" height="300" class="aligncenter size-full wp-image-1785" /></p>
<h2>Step 2: Apply some style to your Menu using CSS</h2>
<p>Lets apply some stylesheet to our menu. Copy following CSS code in your HTML file:</p>
<pre class="brush: css;">
#accordion {
	list-style: none;
	padding: 0 0 0 0;
	width: 170px;
}
#accordion li{
	display: block;
	background-color: #FF9927;
	font-weight: bold;
	margin: 1px;
	cursor: pointer;
	padding: 5 5 5 7px;
	list-style: circle;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	border-radius: 10px;
}
#accordion ul {
	list-style: none;
	padding: 0 0 0 0;
	display: none;
}
#accordion ul li{
	font-weight: normal;
	cursor: auto;
	background-color: #fff;
	padding: 0 0 0 7px;
}
#accordion a {
	text-decoration: none;
}
#accordion a:hover {
	text-decoration: underline;
}
</pre>
<p>Note that in above CSS code, we have applied <a href="http://viralpatel.net/blogs/2009/08/rounded-corner-css-without-images.html">Round Corner CSS</a> to our menu to improve the look. Although this technique works with all the modern web browser, but it will not work with Internet Explorer. If we want to change the look n feel for internet explorer, we may want to include <a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html">IE-Specific stylesheet</a> to our HTML page.<br />
Once we apply the stylesheet, our menu will look like:<br />
<img src="http://img.viralpatel.net/2009/09/accordion-menu-stylesheet.png" alt="accordion-menu-stylesheet" title="accordion-menu-stylesheet" width="237" height="147" class="aligncenter size-full wp-image-1786" /></p>
<h2>Step 3: Give life to your Menu using jQuery</h2>
<p>So our basic skeleton is complete. We have used HTML code to display the Accordion menu content and then have applied CSS stylesheet to improve the usability. Let us add life to this accordion menu using jQuery. Copy following jQuery code to the HTML page: </p>
<pre class="brush: jscript;">
$(&quot;#accordion &gt; li&quot;).click(function(){

	if(false == $(this).next().is(':visible')) {
		$('#accordion &gt; ul').slideUp(300);
	}
	$(this).next().slideToggle(300);
});

$('#accordion &gt; ul:eq(0)').show();
</pre>
<p>If you notice the above code, we have made the first menu item in accordion menu visible. </p>
<pre class="brush: jscript;">
$('#accordion &gt; ul:eq(0)').show();
</pre>
<p>To make a menu item visible by default, just add its index value to the above code. For example to display 1st menu item we added <code>eq(0)</code> in above code.</p>
<h2>Online Demo</h2>
<p>No article is complete without an online demo. Here is the online demo for Accordion Menu.<br />
<iframe src="http://viralpatel.net/blogs/demo/jquery-accordion-menu-example/demo-article.html" height="250px"></iframe></p>
<p><a target="_new" href="http://viralpatel.net/blogs/demo/jquery-accordion-menu-example/"><strong>VIEW DEMO</strong></a>                     </p>
<p><a href="http://viralpatel.net/blogs/demo/jquery-accordion-menu-example/download.zip"><strong>DOWNLOAD</strong></a></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html" title="20 Top jQuery tips &#038; tricks for jQuery programmers">20 Top jQuery tips &#038; tricks for jQuery programmers</a></li><li><a href="http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" title="Understanding jQuery animate() function">Understanding jQuery animate() function</a></li><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/07/delete-row-html-table-clicking-using-jquery.html" title="Delete Row from HTML Table by clicking it using jQuery">Delete Row from HTML Table by clicking it using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/03/how-to-apply-html-user-interface-effects-using-jquery.html" title="How to apply HTML User Interface Effects using jQuery.">How to apply HTML User Interface Effects using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" title="jQuery Live Event">jQuery Live Event</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html&amp;title=Create Simplest Accordion Menu using jQuery&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html&amp;title=Create Simplest Accordion Menu using jQuery" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html&amp;title=Create Simplest Accordion Menu using jQuery" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html&amp;title=Create Simplest Accordion Menu using jQuery" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Changing Form Input (Textbox) Style on Focus using jQuery</title>
		<link>http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html</link>
		<comments>http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html#comments</comments>
		<pubDate>Wed, 16 Sep 2009 14:05:57 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1774</guid>
		<description><![CDATA[User experience has always been a factor to be consider while you design a website. Lot of fields such as Human Computer Interface (HCI) and Usability etc have been studied upon. While designing a user interface, special care should always been taken while placing the text fields and selecting fonts. While lot of web designers [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-1775" title="form-element-style-javascript-textbox" src="http://img.viralpatel.net/2009/09/form-element-style-javascript-textbox.png" alt="form-element-style-javascript-textbox" width="538" height="129" />User experience has always been a factor to be consider while you design a website. Lot of fields such as Human Computer Interface (HCI) and Usability etc have been studied upon. While designing a user interface, special care should always been taken while placing the text fields and selecting fonts. While lot of web designers prefer to display forms in plain vanilla manner, lot of others prefer to give user as much help while filling the forms. Thus the html forms should always have description field with each input field. Also if we can highlight the field that user is filling, it can improve the user experience.</p>
<p>Thus How can we implement the feature where the Input fields which are currently focused are highlighted?</p>
<p>Let us use jQuery and create a simple feature on a HTML Form.</p>
<h2>Step 1: The HTML Code</h2>
<p>We will use following form as a sample HTML Form and apply the Focus effect using jQuery.</p>
<pre class="brush: xml;">
&lt;FORM id=&quot;sample&quot;&gt;
	&lt;TABLE&gt;
	&lt;TR&gt;
		&lt;TD&gt;Name &lt;/TD&gt;
		&lt;TD&gt;&lt;INPUT type=&quot;text&quot;/&gt;&lt;/TD&gt;
	&lt;/TR&gt;
	&lt;TR&gt;
		&lt;TD&gt;Age&lt;/TD&gt;
		&lt;TD&gt;&lt;INPUT type=&quot;text&quot;/&gt;&lt;/TD&gt;
	&lt;/TR&gt;
	&lt;TR&gt;
		&lt;TD&gt;Phone no.&lt;/TD&gt;
		&lt;TD&gt;&lt;INPUT type=&quot;text&quot;/&gt;&lt;/TD&gt;
	&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;/FORM&gt;
</pre>
<h2>Step 2: The CSS Stylesheet</h2>
<p>We will use a simple style class to apply to the focused field. </p>
<pre class="brush: css;">
.focus {
	border: 2px solid #AA88FF;
	background-color: #FFEEAA;
}
</pre>
<h2>Step 3: Add the effect using jQuery</h2>
<p>We will use jQuery to add effect to the form elements. Two events has to be taken care of. While the input field is focused and while the focus is moved to next textbox (blured).</p>
<pre class="brush: jscript;">
$('input[type=&quot;text&quot;]').focus(function() {
	$(this).addClass(&quot;focus&quot;);
});

$('input[type=&quot;text&quot;]').blur(function() {
	$(this).removeClass(&quot;focus&quot;);
});
</pre>
<h2>Online Demo</h2>
<p><iframe src="http://viralpatel.net/blogs/demo/jquery-form-input-textbox-style-focus/article-demo.html" height="150px"></iframe><br />
<a href="http://viralpatel.net/blogs/demo/jquery-form-input-textbox-style-focus/"><strong>View Demo</strong></a></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" title="Understanding jQuery animate() function">Understanding jQuery animate() function</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html" title="Firefox 3.6 Released: With New CSS Gradient Feature">Firefox 3.6 Released: With New CSS Gradient Feature</a></li><li><a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" title="jQuery Live Event">jQuery Live Event</a></li><li><a href="http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html" title="20 Very Useful CSS Stylesheet Tips &#038; Tricks">20 Very Useful CSS Stylesheet Tips &#038; Tricks</a></li><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" title="Create Simplest Accordion Menu using jQuery">Create Simplest Accordion Menu using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html" title="Setting Height of Selectbox (Combobox) in IE">Setting Height of Selectbox (Combobox) in IE</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html&amp;title=Changing Form Input (Textbox) Style on Focus using jQuery&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html&amp;title=Changing Form Input (Textbox) Style on Focus using jQuery" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html&amp;title=Changing Form Input (Textbox) Style on Focus using jQuery" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html&amp;title=Changing Form Input (Textbox) Style on Focus using jQuery" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>20 Top jQuery tips &amp; tricks for jQuery programmers</title>
		<link>http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html</link>
		<comments>http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html#comments</comments>
		<pubDate>Mon, 17 Aug 2009 09:51:54 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[jQuery Effects]]></category>
		<category><![CDATA[jquery tips tricks]]></category>
		<category><![CDATA[tips & tricks]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1665</guid>
		<description><![CDATA[Following are few very useful jQuery Tips and Tricks for all jQuery developers. I am sharing these as I think they will be very useful to you.
Disclaimer: I have not written all of the below code but have collected from various sources from Internet.
1. Optimize performance of complex selectors
Query a subset of the DOM when [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/08/jquery-tips-tricks.png" alt="jquery-tips-tricks" title="jquery-tips-tricks" width="200" height="171" class="alignleft size-full wp-image-1666" />Following are few very useful jQuery Tips and Tricks for all jQuery developers. I am sharing these as I think they will be very useful to you.<br />
<strong>Disclaimer:</strong> I have not written all of the below code but have collected from various sources from Internet.</p>
<h2>1. Optimize performance of complex selectors</h2>
<p>Query a subset of the DOM when using complex selectors drastically improves performance:</p>
<pre class="brush: jscript;">
var subset = $(&quot;&quot;);
$(&quot;input[value^='']&quot;, subset);
</pre>
<h2>2. Set Context and improve the performance</h2>
<p>On the core jQuery function, specify the context parameter when. Specifying the context parameter allows jQuery to start from a deeper branch in the DOM, rather than from the DOM root. Given a large enough DOM, specifying the context parameter should translate to performance gains.</p>
<pre class="brush: jscript;">
$(&quot;input:radio&quot;, document.forms[0]);
</pre>
<h2>3. Live Event Handlers</h2>
<p>Set an event handler for any element that matches a selector, even if it gets added to the DOM after the initial page load:</p>
<pre class="brush: jscript;">
$('button.someClass').live('click', someFunction);
</pre>
<p>This allows you to load content via ajax, or add them via javascript and have the event handlers get set up properly for those elements automatically.</p>
<p>Likewise, to stop the live event handling:</p>
<pre class="brush: jscript;">
$('button.someClass').die('click', someFunction);
</pre>
<p>These live event handlers have a few limitations compared to regular events, but they work great for the majority of cases. Live event will work starting from jQuery 1.3</p>
<h2>4. Checking the Index</h2>
<p>jQuery has .index but it is a pain to use as you need the list of elements and pass in the element you want the index of</p>
<pre class="brush: jscript;">
var index = e.g $('#ul&gt;li').index( liDomObject );
</pre>
<p>The following is easier:</p>
<p>if you want to know the index of an element within a set, e.g. list items within a unordered list:</p>
<pre class="brush: jscript;">
$(&quot;ul &gt; li&quot;).click(function ()
{
    var index = $(this).prevAll().length;
});
</pre>
<h2>5. Use jQuery data method</h2>
<p>jQuery&#8217;s <a rel="nofollow" target="_new" href="http://docs.jquery.com/Core/data">data() method</a> is useful and not well known. It allows you to bind data to DOM elements without modifying the DOM.</p>
<h2>6. Fadeout Slideup effect to remove an element</h2>
<p>Combine more than one effects in jQuery to animate and remove an element from DOM.</p>
<pre class="brush: jscript;">
$(&quot;#myButton&quot;).click(function() {
         $(&quot;#myDiv&quot;).fadeTo(&quot;slow&quot;, 0.01, function(){ //fade
             $(this).slideUp(&quot;slow&quot;, function() { //slide up
                 $(this).remove(); //then remove from the DOM
             });
         });
});
</pre>
<h2>7. Checking if an element exists</h2>
<p>Use following snippet to check whether an element exists or not.  </p>
<pre class="brush: jscript;">
if ($(&quot;#someDiv&quot;).length) {
    //hooray!!! it exists...
}
</pre>
<h2>8. Add dynamically created elements into the DOM</h2>
<p>Use following code snippet to create a DIV dynamically and add it into the DOM.<br />
<strong>Further Reading:</strong> <a href="http://viralpatel.net/blogs/2009/03/dynamically-add-remove-rows-in-html-table-using-javascript.html">Dynamically Add/Remove rows in HTML table using JavaScript</a></p>
<pre class="brush: jscript;">
var newDiv = $('&lt;div&gt;&lt;/div&gt;');
newDiv.attr(&quot;id&quot;,&quot;myNewDiv&quot;).appendTo(&quot;body&quot;);
</pre>
<h2>9. Line breaks and chainability</h2>
<p>Instead of doing:</p>
<pre class="brush: jscript;">
$(&quot;a&quot;).hide().addClass().fadeIn().hide();
</pre>
<p>You can increase readability like so:</p>
<pre class="brush: jscript;">
$(&quot;a&quot;)
  .hide()
  .addClass()
  .fadeIn()
  .hide();
</pre>
<h2>10. Creating custom selectors</h2>
<pre class="brush: jscript;">
$.extend($.expr[':'], {
    over100pixels: function(a) {
        return $(a).height() &gt; 100;
    }
});

$('.box:over100pixels').click(function() {
    alert('The element you clicked is over 100 pixels high');
});
</pre>
<h2>11. Cloning an object in jQuery</h2>
<p>Use .clone() method of jQuery to clone any DOM object in JavaScript.</p>
<pre class="brush: jscript;">
// Clone the DIV
var cloned = $('#somediv').clone();
</pre>
<p>jQuery&#8217;s clone() method does not clone a JavaScript object. To clone JavaScript object, use following code.</p>
<pre class="brush: jscript;">
// Shallow copy
var newObject = jQuery.extend({}, oldObject);

// Deep copy
var newObject = jQuery.extend(true, {}, oldObject);
</pre>
<h2>12. Test if something is hidden using jQuery</h2>
<p>We use .hide(), .show() methods in jquery to change the visibility of an element. Use following code to check the whether an element is visible or not.</p>
<pre class="brush: jscript;">
if($(element).is(&quot;:visible&quot;) == &quot;true&quot;) {
       //The element is Visible
}
</pre>
<h2>13. Alternate way of Document Ready</h2>
<pre class="brush: jscript;">
//Instead of
$(document).ready(function() {
	//document ready
});
//Use
$(function(){
	//document ready
});
</pre>
<h2>14. Selecting an element with . (period) in its ID</h2>
<p>Use backslash in the selector to select the element having period in its ID.</p>
<pre class="brush: jscript;">
$(&quot;#Address\\.Street&quot;).text(&quot;Enter this field&quot;);
</pre>
<h2>15. Counting immediate child elements</h2>
<p>If you want to count all the DIVs present in the element #foo</p>
<pre class="brush: jscript;">
&lt;div id=&quot;foo&quot;&gt;
  &lt;div id=&quot;bar&quot;&gt;&lt;/div&gt;
  &lt;div id=&quot;baz&quot;&gt;
    &lt;div id=&quot;biz&quot;&gt;
  &lt;/div&gt;
  &lt;span&gt;&lt;span&gt;
&lt;/div&gt;

//jQuery code to count child elements
$(&quot;#foo &gt; div&quot;).size()
</pre>
<h2>16. Make an element to &#8220;FLASH&#8221;</h2>
<pre class="brush: jscript;">
jQuery.fn.flash = function( color, duration )
{
    var current = this.css( 'color' );
    this.animate( { color: 'rgb(' + color + ')' }, duration / 2 );
    this.animate( { color: current }, duration / 2 );
}
//Then use the above function as:
$( '#importantElement' ).flash( '255,0,0', 1000 );
</pre>
<h2>17. Center an element on the Screen</h2>
<pre class="brush: jscript;">
jQuery.fn.center = function () {
    this.css(&quot;position&quot;,&quot;absolute&quot;);
    this.css(&quot;top&quot;, ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + &quot;px&quot;);
    this.css(&quot;left&quot;, ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + &quot;px&quot;);
    return this;
}

//Use the above function as:
$(element).center();
</pre>
<h2>18. Getting Parent DIV using closest</h2>
<p>If you want to find the wrapping DIV element (regardless of the ID on that DIV) then you&#8217;ll want this jQuery selector:</p>
<pre class="brush: jscript;">
$(&quot;#searchBox&quot;).closest(&quot;div&quot;);
</pre>
<h2>19. Disable right-click contextual menu</h2>
<p>There&#8217;s many Javascript snippets available to disable right-click contextual menu, but JQuery makes things a lot easier:</p>
<pre class="brush: jscript;">
$(document).ready(function(){
    $(document).bind(&quot;contextmenu&quot;,function(e){
        return false;
    });
});
</pre>
<h2>20. Get mouse cursor x and y axis</h2>
<p>This script will display the x and y value &#8211; the coordinate of the mouse pointer.</p>
<pre class="brush: jscript;">
$().mousemove(function(e){
	//display the x and y axis values inside the P element
    $('p').html(&quot;X Axis : &quot; + e.pageX + &quot; | Y Axis &quot; + e.pageY);
});

&lt;p&gt;&lt;/p&gt;
</pre>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html" title="Create Simplest Accordion Menu using jQuery">Create Simplest Accordion Menu using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2010/03/understanding-jquery-animate-function.html" title="Understanding jQuery animate() function">Understanding jQuery animate() function</a></li><li><a href="http://viralpatel.net/blogs/2009/10/jquery-bounce-effect-bounce-html-js.html" title="Fantastic Bouncy Effect using jQuery/JavaScript">Fantastic Bouncy Effect using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/07/delete-row-html-table-clicking-using-jquery.html" title="Delete Row from HTML Table by clicking it using jQuery">Delete Row from HTML Table by clicking it using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/03/how-to-apply-html-user-interface-effects-using-jquery.html" title="How to apply HTML User Interface Effects using jQuery.">How to apply HTML User Interface Effects using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/12/jquery-live-events.html" title="jQuery Live Event">jQuery Live Event</a></li><li><a href="http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html" title="20 Very Useful CSS Stylesheet Tips &#038; Tricks">20 Very Useful CSS Stylesheet Tips &#038; Tricks</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html&amp;title=20 Top jQuery tips &#038; tricks for jQuery programmers&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html&amp;title=20 Top jQuery tips &#038; tricks for jQuery programmers" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html&amp;title=20 Top jQuery tips &#038; tricks for jQuery programmers" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html&amp;title=20 Top jQuery tips &#038; tricks for jQuery programmers" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Sum HTML Textbox Values using jQuery / JavaScript</title>
		<link>http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html</link>
		<comments>http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html#comments</comments>
		<pubDate>Tue, 21 Jul 2009 15:55:45 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Sum Textbox values]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1583</guid>
		<description><![CDATA[
Here is a small code snippet to sum the values of all textboxes in a form in JavaScript using jQuery. I wrote it for some functionality and thought to share it with you all. The requirement is simple, whenever user modify the value of a textbox, the fresh sum should be calculated and displayed on [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/07/sum-html-textbox-value-javascript.png" alt="sum-html-textbox-value-javascript" title="sum-html-textbox-value-javascript" width="303" height="189" class="aligncenter size-full wp-image-1584" /><br />
Here is a small code snippet to sum the values of all textboxes in a form in JavaScript using jQuery. I wrote it for some functionality and thought to share it with you all. The requirement is simple, whenever user modify the value of a textbox, the fresh sum should be calculated and displayed on the form. I used jQuery for this as it provides simple way of selecting elements and iterating through them. </p>
<h2>Source Code</h2>
<p>Following is the complete source code.</p>
<pre class="brush: xml;">
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;Sum Html Textbox Values using jQuery/JavaScript&lt;/title&gt;
		&lt;style&gt;
			body {
				font-family: sans-serif;
			}
			#summation {
				font-size: 18px;
				font-weight: bold;
				color:#174C68;
			}
			.txt {
				background-color: #FEFFB0;
				font-weight: bold;
				text-align: right;
			}
		&lt;/style&gt;
		&lt;script src=&quot;jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
&lt;table width=&quot;300px&quot; border=&quot;1&quot; style=&quot;border-collapse:collapse;background-color:#E8DCFF&quot;&gt;
	&lt;tr&gt;
		&lt;td width=&quot;40px&quot;&gt;1&lt;/td&gt;
		&lt;td&gt;Butter&lt;/td&gt;
		&lt;td&gt;&lt;input class=&quot;txt&quot; type=&quot;text&quot; name=&quot;txt&quot;/&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;2&lt;/td&gt;
		&lt;td&gt;Cheese&lt;/td&gt;
		&lt;td&gt;&lt;input class=&quot;txt&quot; type=&quot;text&quot; name=&quot;txt&quot;/&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;3&lt;/td&gt;
		&lt;td&gt;Eggs&lt;/td&gt;
		&lt;td&gt;&lt;input class=&quot;txt&quot; type=&quot;text&quot; name=&quot;txt&quot;/&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;4&lt;/td&gt;
		&lt;td&gt;Milk&lt;/td&gt;
		&lt;td&gt;&lt;input class=&quot;txt&quot; type=&quot;text&quot; name=&quot;txt&quot;/&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;5&lt;/td&gt;
		&lt;td&gt;Bread&lt;/td&gt;
		&lt;td&gt;&lt;input class=&quot;txt&quot; type=&quot;text&quot; name=&quot;txt&quot;/&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;6&lt;/td&gt;
		&lt;td&gt;Soap&lt;/td&gt;
		&lt;td&gt;&lt;input class=&quot;txt&quot; type=&quot;text&quot; name=&quot;txt&quot;/&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr id=&quot;summation&quot;&gt;
		&lt;td&gt;&amp;nbsp;&lt;/td&gt;
		&lt;td align=&quot;right&quot;&gt;Sum :&lt;/td&gt;
		&lt;td align=&quot;center&quot;&gt;&lt;span id=&quot;sum&quot;&gt;0&lt;/span&gt;&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;

&lt;script&gt;
	$(document).ready(function(){

		//iterate through each textboxes and add keyup
		//handler to trigger sum event
		$(&quot;.txt&quot;).each(function() {

			$(this).keyup(function(){
				calculateSum();
			});
		});

	});

	function calculateSum() {

		var sum = 0;
		//iterate through each textboxes and add the values
		$(&quot;.txt&quot;).each(function() {

			//add only if the value is number
			if(!isNaN(this.value) &amp;&amp; this.value.length!=0) {
				sum += parseFloat(this.value);
			}

		});
		//.toFixed() method will roundoff the final sum to 2 decimal places
		$(&quot;#sum&quot;).html(sum.toFixed(2));
	}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Let us step by step see what above code is doing. </p>
<ol>
<li>First the <code>$(document).ready()</code> is called which gets triggered whenever the webpage is loaded.</li>
<li>Inside <code>$(document).ready()</code>, we selected all textboxes by the class name &#8220;.txt&#8221; and iterate through each of them and added event handler on keydown event. Thus whenever keypress event will occur, the code will trigger <code>calculateSum()</code> function. Note that you may want to change the selector code that suits your html elements. In this case we selected textboxes based on class=&#8221;txt&#8221; as all textbox has this class.
</li>
<li>The keydown event triggers the function <code>calculateSum()</code>. In this function again we iterate through each textboxes and sum up the values in a variable sum. Note that we have checked whether the value is number before adding it to the sum.</li>
<li>Finally we update the innerHTML property of span #sum using <code>$("#sum").html(sum)</code> code. You may want to display the sum in some textbox or some other place.
</li>
</ol>
<h2>Online Demo</h2>
<p><iframe src="http://viralpatel.net/blogs/demo/sum-textbox-value-javascript.html" width="100%" height="230px"></iframe><br />
<a target="_new" href="http://viralpatel.net/blogs/demo/sum-textbox-value-javascript.html">Click here to view online Demo</a></p>
<div id="relatedpost" style="background-color:#FFF1A8; padding:3px;"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/07/delete-row-html-table-clicking-using-jquery.html" title="Delete Row from HTML Table by clicking it using jQuery">Delete Row from HTML Table by clicking it using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/05/implement-drag-and-drop-example-jquery-javascript-html.html" title="Drag and Drop Example using jQuery JavaScript in HTML">Drag and Drop Example using jQuery JavaScript in HTML</a></li><li><a href="http://viralpatel.net/blogs/2009/04/jquery-tabs-create-html-tabs-using-jquery-ui.html" title="jQuery tabs: Create HTML tabs using jQuery UI">jQuery tabs: Create HTML tabs using jQuery UI</a></li><li><a href="http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html" title="jQuery AJAX Tutorial, Example: Simplify Ajax development with jQuery">jQuery AJAX Tutorial, Example: Simplify Ajax development with jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/04/tutorial-handle-browser-events-using-jquery-javascript-framework.html" title="Tutorial: Handle browser events using jQuery JavaScript framework">Tutorial: Handle browser events using jQuery JavaScript framework</a></li><li><a href="http://viralpatel.net/blogs/2009/03/how-to-apply-html-user-interface-effects-using-jquery.html" title="How to apply HTML User Interface Effects using jQuery.">How to apply HTML User Interface Effects using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2008/12/set-maxlength-of-textarea-input-using-jquery-javascript.html" title="How to:Set Maxlength of Textarea using jQuery/JavaScript">How to:Set Maxlength of Textarea using jQuery/JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2008/12/ajax-post-method-example-using-javascript-jquery.html" title="AJAX Post method example using javascript &#038; jQuery">AJAX Post method example using javascript &#038; jQuery</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html&amp;title=Sum HTML Textbox Values using jQuery / JavaScript&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html&amp;title=Sum HTML Textbox Values using jQuery / JavaScript" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html&amp;title=Sum HTML Textbox Values using jQuery / JavaScript" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html&amp;title=Sum HTML Textbox Values using jQuery / JavaScript" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
