<?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>JavaBeat &#187; Ganesh Prakhya</title>
	<atom:link href="http://www.javabeat.net/author/ganeshp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Fri, 24 May 2013 01:32:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Loading XML using jQuery AJAX</title>
		<link>http://www.javabeat.net/2013/03/xml-jquery-ajax/</link>
		<comments>http://www.javabeat.net/2013/03/xml-jquery-ajax/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 13:36:07 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=6118</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In our previous articles, we discussed about how jQuery AJAX works and also various jQuery global AJAX event handlers available in jQuery. In this article, we&#8217;ll focus on accessing an XML document residing at the server, reading and displaying content of the XML using jQuery AJAX. In the following code example, we send an AJAX [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p>In our previous articles, we discussed about <a href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" target="_blank">how jQuery AJAX works</a> and also <a href="http://www.javabeat.net/2013/02/jquery-global-ajax-event-handlers/" target="_blank">various jQuery global AJAX event handlers</a> available in jQuery. In this article, we&#8217;ll focus on accessing an <strong>XML</strong> document residing at the server, reading and displaying content of the XML using <strong>jQuery AJAX</strong>. In the following code example, we send an <strong>AJAX</strong> request to read the XML document we needed and we process the response from the AJAX request to display the results. We&#8217;ll also see how we can detect any errors occurred during AJAX request.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to jQuery Global Ajax Event Handlers" href="http://www.javabeat.net/2013/02/jquery-global-ajax-event-handlers/" rel="bookmark">jQuery Global Ajax Event Handlers</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<pre class="brush: java; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
	$(&quot;#loadBtn&quot;).click(function() {
		$.ajax({
			type: &quot;GET&quot;,
			url: &quot;products.xml&quot;,
			datatype: &quot;xml&quot;,
			error: function(jqXHR, textStatus, errorThrown) {
				console.log('Error: ' + errorThrown);
			},
			success: function(xml) {
				console.log('AJAX Request is succeded.');

				var productsTable = '';
				productsTable += '&lt;table id=&quot;productsTable&quot;
                       cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; border=&quot;1&quot;&gt;' ;

				productsTable += '&lt;thead&gt;&lt;td&gt;Id&lt;/td&gt;
                       &lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Price&lt;/td&gt;&lt;td&gt;Discount&lt;/td&gt;&lt;/thead&gt;';

				$(xml).find('product').each(function(){
					productsTable += '&lt;tr&gt;';
					productsTable += '&lt;td&gt;';
					productsTable += $(this).find('id').text();
					productsTable += '&lt;/td&gt;';

					productsTable += '&lt;td&gt;';
					productsTable += $(this).find('name').text();
					productsTable += '&lt;/td&gt;';

					productsTable += '&lt;td&gt;';
					productsTable += $(this).find('price').text();
					productsTable += '&lt;/td&gt;';

					productsTable += '&lt;td&gt;';
					productsTable += $(this).find('discount').text();
					productsTable += '&lt;/td&gt;';

					productsTable += '&lt;/tr&gt;';
				});
				productsTable += '&lt;/table&gt;';
				$(&quot;#products&quot;).append(productsTable);
			}
		});
	});
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

Please click to load the products from server:
&lt;input type=&quot;button&quot; id=&quot;loadBtn&quot; value=&quot;Load XML&quot;/&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div id=products&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>In the above code example, we sent an AJAX request to the XML document &#8216;<em>products.xml</em>&#8216; which is at the same server location as the executing HTML file. However, we can also use relative paths to access various server resources.</p>
<p>Note that we specified various parameters while sending the AJAX request. For example, we configured the request &#8216;type&#8217; as &#8216;GET&#8217;, &#8216;url&#8217; to &#8216;products.xml&#8217; and &#8216;datatype&#8217; as &#8216;xml&#8217;. <span style="color: #000080;"><strong>The &#8216;datatype&#8217; parameter indicates the type of the response we&#8217;re expecting from the server</strong></span>.</p>
<p>The following is the XML we used in this example in the products.xml.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;products&gt;
	&lt;product&gt;
		&lt;id&gt;P-22345&lt;/id&gt;
		&lt;name&gt;LCD Television&lt;/name&gt;
		&lt;price&gt;$500&lt;/price&gt;
		&lt;discount&gt;5%&lt;/discount&gt;
	&lt;/product&gt;
	&lt;product&gt;
		&lt;id&gt;P-13245&lt;/id&gt;
		&lt;name&gt;Mac Mini&lt;/name&gt;
		&lt;price&gt;$700&lt;/price&gt;
		&lt;discount&gt;2%&lt;/discount&gt;
	&lt;/product&gt;
	&lt;product&gt;
		&lt;id&gt;P-52346&lt;/id&gt;
		&lt;name&gt;Home Theatre&lt;/name&gt;
		&lt;price&gt;$500&lt;/price&gt;
		&lt;discount&gt;1%&lt;/discount&gt;
	&lt;/product&gt;
	&lt;product&gt;
		&lt;id&gt;P-78385&lt;/id&gt;
		&lt;name&gt;Laptop Computer&lt;/name&gt;
		&lt;price&gt;$1500&lt;/price&gt;
		&lt;discount&gt;5%&lt;/discount&gt;
	&lt;/product&gt;
	&lt;product&gt;
		&lt;id&gt;P-78385&lt;/id&gt;
		&lt;name&gt;Desktop Computer&lt;/name&gt;
		&lt;price&gt;$1000&lt;/price&gt;
		&lt;discount&gt;7%&lt;/discount&gt;
	&lt;/product&gt;
&lt;/products&gt;
</pre>
<p style="text-align: left;">When we click on the button &#8216;Load XML&#8217;, the XML content is loaded from the server and displayed in a tabular format as shown in the below screen capture.<br />
<img class=" wp-image-6119 aligncenter" alt="load-xml" src="http://www.javabeat.net/wp-content/uploads/2013/03/load-xml.png" width="489" height="305" /></p>
<p><span style="color: #000080;"><strong>We can specify a number of parameters in the AJAX request as key/value pairs. All parameters are optional</strong></span>. <span style="text-decoration: underline;">In this code example we&#8217;re using &#8216;type&#8217;, &#8216;url&#8217;, &#8216;datatype&#8217;, &#8216;error&#8217;, and &#8216;success&#8217; parameters</span>. The &#8216;type&#8217; parameter specifies the request type (GET or POST), &#8216;url&#8217; specifies the URL of the resource in the server to access, &#8216;datatype&#8217; is to indicate what kind of content to expect as part of the response (other possible value is JSON to handle JSON response, html for HTML response, text for pure text response, script to evaluate the response as JavaScript and returns it as plain text). We have &#8216;error&#8217; and &#8216;success&#8217; callback methods to handle any errors in the AJAX request or to display the data upon successful request respectively.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to jQuery Global Ajax Event Handlers" href="http://www.javabeat.net/2013/02/jquery-global-ajax-event-handlers/" rel="bookmark">jQuery Global Ajax Event Handlers</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a></p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fauthor%2Fganeshp%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/author/ganeshp/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/author/ganeshp/feed/" data-count="vertical" data-text="" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/03/xml-jquery-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Effects &#8211; Hide, Show and Toggle</title>
		<link>http://www.javabeat.net/2013/02/jquery-effects/</link>
		<comments>http://www.javabeat.net/2013/02/jquery-effects/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 13:55:51 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=6010</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>We can create great animations using jQuery. jQuery provides various methods to create animation effects in the web pages. We can use standard animation effects those are most frequently used and also we can customize the effects for better visuals. In this article, we&#8217;ll discuss about jQuery basic effects. Let&#8217;s discuss about three main methods [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><span style="color: #000080;"><strong>We can create great animations using jQuery</strong></span>. jQuery provides various methods to create animation effects in the web pages. We can use standard animation effects those are most frequently used and also we can customize the effects for better visuals. In this article, we&#8217;ll discuss about jQuery <strong>basic effects</strong>. Let&#8217;s discuss about <span style="color: #000080;"><strong><span style="text-decoration: underline;">three main methods which provides basic effects. i.e., .show(), .hide() and .toggle()</span></strong></span>. If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Manipulating Styles with jQuery" href="http://www.javabeat.net/2013/02/manipulating-styles-with-jquery/" rel="bookmark">Manipulating Styles with jQuery</a></li>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<h1 style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #000080; text-decoration: underline;">jQuery Effects</span></span></h1>
<p>The following example shows, hides and toggles the display of a paragraph text using basic effects.</p>
<pre class="brush: java; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
.paragraph {font-size:20px;color:#0000cc}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
	$(&quot;#show&quot;).click(function() {
		$(&quot;p&quot;).show(1000, function(){
			console.log('Paragraph is shown.');
		});
	});

	$(&quot;#hide&quot;).click(function() {
		$(&quot;p&quot;).hide(1000, function(){
			console.log('Paragraph is hidden.');
		});
	});

	$(&quot;#toggle&quot;).click(function() {
		$(&quot;p&quot;).toggle(1000);
	});

});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;br/&gt;
&lt;p&gt;This is a simple paragraph text.&lt;/p&gt;&lt;br/&gt;
&lt;input type=&quot;button&quot; id=&quot;show&quot; value=&quot;Show&quot;/&gt;
&lt;input type=&quot;button&quot; id=&quot;hide&quot; value=&quot;Hide&quot;/&gt;
&lt;input type=&quot;button&quot; id=&quot;toggle&quot; value=&quot;Toggle&quot;/&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>When we click on the Hide button, the paragraph hides with slow transition effect. We also called a callback function once the hiding effect completes.</p>
<p><img class="size-full wp-image-6012 aligncenter" alt="hide-effect" src="http://www.javabeat.net/wp-content/uploads/2013/02/hide-effect.png" width="546" height="186" /></p>
<p>When we click on Show button the paragraph will be shown with slow transition effect as shown in the below. Again, the callback function is invoked once the showing effect is completed.</p>
<p><img class="size-full wp-image-6011 aligncenter" alt="show-effect" src="http://www.javabeat.net/wp-content/uploads/2013/02/show-effect.png" width="541" height="238" /></p>
<h2><strong>.show()</strong></h2>
<p>The .show() method displays the matched elements if they&#8217;re hidden. This method takes several arguments like duration. We can have a callback function to be invoked once the .show() method completes execution. In the following code, the value 1000 represents the duration of the animation.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).show(1000, function(){
    console.log('Paragraph is shown.');
});
</pre>
<h2><strong>.hide()</strong></h2>
<p>The .hide() method hides the matched elements if they&#8217;re in visible state. This method also takes several arguments like duration. The callback function is invoked once the .hide() method completes execution. In the following code, the value 1000 represents the duration of the animation.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).hide(1000, function(){
    console.log('Paragraph is hidden.');
});
</pre>
<h2><strong>.toggle()</strong></h2>
<p>The .toggle() method either displays or hides the matched elements based on their current state.</p>
<pre class="brush: java; title: ; notranslate">
  $(&quot;p&quot;).toggle(1000);
</pre>
<p><span style="color: #000080;"><strong>We can create basic animation effects using .show(), .hide() and .toggle() methods in jQuery</strong></span>. These three methods have an numeric argument to represent the duration of the animation. <strong>The default value is 400</strong>. The greater the duration the longer the animation runs. We can also have callback functions to these methods which is called once the method completes execution.</p>
<h2><strong>Quick Summary of Other jQuery Effects</strong></h2>
<h2><strong>.animate() </strong></h2>
<p>The .animate() method performs an animation on CSS properties. The animation will be peformed towards to given CSS properties.</p>
<pre class="brush: java; title: ; notranslate">
$('#myDiv').animate({
	opacity: .5,
	width: 'linear',
	height: '75%'
   }, 8000, function() {

   console.log('animate() completed);
});
</pre>
<h2><strong>.queue()</strong></h2>
<p>The .queue() method shows or manipulates the sequence of functions to be executed on the matched elements. We can have a number of functions to exeucte in a queue as shown below and the functions will be executed sequentially.</p>
<pre class="brush: java; title: ; notranslate">
function myAnimation() {
	myDiv.animate({left:'+=10'},3000);
	myDiv.show(&quot;slow&quot;);
        myDiv.hide(&quot;slow&quot;);
	myDiv.animate({right:'+=20'},3000);
}
</pre>
<p>The default name of the queue is &#8216;fx&#8217; which is the standard effects queue.</p>
<h2><strong>.clearQueue()</strong></h2>
<p>The .clearQueue() method removes all functions from the queue those are not yet executed.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
$(&quot;#animationDiv&quot;).clearQueue();
</pre>
<h2><strong>.delay()</strong></h2>
<p>The .delay() method delays the execution of the functions in the queue by putting a timer.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#animationDiv&quot;).show(&quot;slow&quot;).delay(1000).fadeIn(500);
</pre>
<h2><strong>.dequeue()</strong></h2>
<p>The .dequeue() method executes the next function in the queue. When called, the next function in the queue will be removed from queue and then executed. In order to continue the sequence of execution, this function in turn should call .dequeue().</p>
<pre class="brush: java; title: ; notranslate">
function myAnimation() {
	myDiv.animate({left:'+=10'},3000);
	myDiv.show(&quot;slow&quot;);
        myDiv.hide(&quot;slow&quot;);
        myDiv.queue(function() {
	  $(this).addClass('newitemclass');
	  $(this).dequeue();
        });
	myDiv.animate({right:'+=20'},3000);
}
</pre>
<h2><strong>.finish()</strong></h2>
<p>The .finish() method completes the animation by stopping the currently running animation, and by removing all queued functions.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#animationDiv&quot;).finish();
</pre>
<h2><strong>jQuery.fx.interval</strong></h2>
<p>Indicates the rate of animations trigger (in milliseconds). This property can be used to adjust the number of frames per second in the animation. Default is 13 milliseconds. Making this value lower may have performance issue.</p>
<pre class="brush: java; title: ; notranslate">
jQuery.fx.interval = 100;
// animation code
</pre>
<h2><strong>jQuery.fx.off</strong></h2>
<p>This property disables all animations globally. When this property is defined with &#8216;true&#8217;, all the animation methods will stop effects by setting to their final state. This is particularly useful in cases where jQuery is used in low-resource devices.</p>
<pre class="brush: java; title: ; notranslate">
var disableFx = function() {
	$.fx.off = 'true';
};
</pre>
<h2><strong>.stop()</strong></h2>
<p>The .stop() method stops the currently executing animation in the queue.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#stopBtn&quot;).click(function() {
    $(&quot;#animationDiv&quot;).stop();
});
</pre>
<h2><strong>.fadeIn()</strong></h2>
<p>The .fadeIn() methods renders the matched elements with fading effect to opaque.</p>
<pre class="brush: java; title: ; notranslate">
 $('#myDiv').fadeIn('slow', function() {
	console.log('fadeIn completed');
  });
</pre>
<h2><strong>.fadeOut()</strong></h2>
<p>The .fadeOut() method hides the matched elements by fading out them to transparent.</p>
<pre class="brush: java; title: ; notranslate">
 $('#myDiv').fadeOut('slow',
   function() {
    console.log('fadeOut is completed.');
   });
</pre>
<h2><strong>.fadeTo()</strong></h2>
<p>The .fadeTo() method will adjust the opacity of the matched elements to the given value.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).click(function () {
   $(this).fadeTo(&quot;slow&quot;, 0.47);
});
</pre>
<h2><strong>.fadeToggle()</strong></h2>
<p>The .fadeToggle() method toggles the display of the matched elements by animating opacity.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).fadeToggle(&quot;fast&quot;, &quot;linear&quot;);
</pre>
<h2><strong>.slideDown()</strong></h2>
<p>The .slideDown() method renders the matched elements with a sliding effect.</p>
<pre class="brush: java; title: ; notranslate">
$('#imageDiv').slideDown('slow', function() {
   console.log(&quot;slideDown completed.&quot;);
});
</pre>
<h2><strong>.slideToggle()</strong></h2>
<p>The .slideToggle() method either displays or hides the matched elements with sliding effect.</p>
<pre class="brush: java; title: ; notranslate">
$('#imageDiv').slideToggle('slow', function() {
   console.log(&quot;slideToggle completed.&quot;);
});
</pre>
<h2><strong>.slideUp()</strong></h2>
<p>The .slideUp() method hides the matched elements with sliding effect.</p>
<pre class="brush: java; title: ; notranslate">
$('#imageDiv').slideUp('slow', function() {
   console.log(&quot;slideUp completed.&quot;);
});
</pre>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Manipulating Styles with jQuery" href="http://www.javabeat.net/2013/02/manipulating-styles-with-jquery/" rel="bookmark">Manipulating Styles with jQuery</a></li>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/02/jquery-effects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with DOM Attributes using jQuery</title>
		<link>http://www.javabeat.net/2013/02/working-with-dom-attributes-using-jquery/</link>
		<comments>http://www.javabeat.net/2013/02/working-with-dom-attributes-using-jquery/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 13:27:28 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5999</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In the previous article we learned about manipulating CSS class using jQuery. In this article, we discuss about dealing with DOM attributes using jQuery. jQuery provides flexible methods to get or set DOM attributes and values of the matched elements, and to get or set property values of the matched elements and also to get [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>In the <a href="http://www.javabeat.net/2013/02/css-class-manipulation-with-jquery/" target="_blank">previous</a> article we learned about manipulating CSS class using jQuery. In this article, we discuss about dealing with DOM attributes using jQuery. jQuery provides flexible methods to get or set DOM attributes and values of the matched elements, and to get or set property values of the matched elements and also to get or set matched element&#8217;s HTML content. We can also remove an attribute or a property using these methods. <span style="color: #000080;"><strong>The following is the summary of jQuery methods we can use to manipulate DOM attributes or properties dynamically to a achieve variety of functionality</strong></span>.</p>
<ul>
<li><i><i>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></i></i></li>
</ul>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<h1 style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #000080; text-decoration: underline;">DOM Attributes using jQuery</span></span></h1>
<p>The following are the methods jQuery supports to work with DOM Attributes. A working example and output screen capture is provided for each of the methods. The following code snippet reads and sets the attribute values.</p>
<pre class="brush: java; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
	console.log(&quot;div id is: &quot; + $(&quot;#mainDiv&quot;).attr(&quot;id&quot;));
	console.log(&quot;strong text title is: &quot; + $(&quot;strong&quot;).attr(&quot;title&quot;));

	$(&quot;#updateAttr&quot;).click(function(){
		$(&quot;strong&quot;).attr(&quot;title&quot;,&quot;UPDATED TITLE&quot;);
	});
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;h1&gt;.attr() Demo&lt;/h1&gt;
	&lt;div id=&quot;mainDiv&quot;&gt;
		&lt;strong title=&quot;Title for strong text.&quot;&gt;
                    This text is inside mainDiv.
                &lt;/strong&gt;&lt;br/&gt;
		&lt;input type=&quot;button&quot; id=&quot;updateAttr&quot; value=&quot;Update&quot;/&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The following screen describes how we can read element’s attributes.<br />
<img class="size-full wp-image-6001 aligncenter" alt="dom-attributes-get-attr" src="http://www.javabeat.net/wp-content/uploads/2013/02/dom-attributes-get-attr.png" width="541" height="245" /></p>
<p>Once we click on the Update button, the title of the strong text has been updated. Please see the following screen capture for the updated title.</p>
<p><img class="size-full wp-image-6000 aligncenter" alt="dom-attributes-set-attr" src="http://www.javabeat.net/wp-content/uploads/2013/02/dom-attributes-set-attr.png" width="544" height="231" /></p>
<h2><strong>.attr()</strong></h2>
<p>The .attr() method either gets or sets the value of the attribute from the matched elements.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;strong&quot;).attr(&quot;title&quot;)
$(&quot;strong&quot;).attr(&quot;title&quot;, &quot;Updated Title&quot;)
</pre>
<h2><strong>.removeAttr()</strong></h2>
<p>The .removeAttr() method removes the attribute from the matched elements.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
$(&quot;strong&quot;).removeAttr(&quot;title&quot;);
</pre>
<h2><strong>.prop()</strong></h2>
<p>The .prop() method gets or sets the value of the property from the matched elements.</p>
<pre class="brush: java; title: ; notranslate">
$(“#myChkBox”).prop(&quot;checked&quot;)
$(“#myChkBox”).prop(&quot;checked&quot;,”true”)
</pre>
<h2><strong>.removeProp()</strong></h2>
<p>The .removeProp() method removes the property from the matched elements.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#myChkBox&quot;).removeProp(&quot;checked&quot;);
</pre>
<h2><strong>.html()</strong></h2>
<p>The .html() method gets or sets HTML content of the matched elements.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#mainDiv&quot;).html();
$(&quot;#mainDiv&quot;).html(&quot;&amp;lt;h1&amp;gt;Heading1&amp;lt;/h1&amp;gt;&quot;);
</pre>
<h2><strong>.val()</strong></h2>
<p>The .val() method gets or sets the value of the matched elements.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#myTextInput&quot;).val()
$(&quot;#myTextInput&quot;).val(‘New value’)
</pre>
<ul>
<li><i><i>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></i></i></li>
</ul>
<p>The DOM manipulation method .attr() is very useful to read or to dynamically set the attributes along with values. Also .prop() method is useful to deal with properties. For instance, using .prop() method we can verify the checked property of checkbox. We use .removeAttr() and .removeProp() methods to remove attributes and properties respectively. The .html() method is flexible in either getting or setting full HTML content of the matched elements. The .html() is particularly useful in setting HTML content from AJAX response. Lastly, the .val() method is used to get or set the value of matched element, for instance we can either read or set the text input value.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/02/working-with-dom-attributes-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Global Ajax Event Handlers</title>
		<link>http://www.javabeat.net/2013/02/jquery-global-ajax-event-handlers/</link>
		<comments>http://www.javabeat.net/2013/02/jquery-global-ajax-event-handlers/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 16:07:35 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5822</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In the jQuery Ajax Introduction, we discussed about sending Ajax requests and processing returned data using jQuery. In this article we’ll discuss about Ajax event handler methods. These Ajax event handler methods are invoked when Ajax related events are triggered like sending an Ajax request, completion of an Ajax request, and error during Ajax request [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>In the <a href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/">jQuery Ajax Introduction</a>, we discussed about sending Ajax requests and processing returned data using jQuery. In this article we’ll discuss about Ajax event handler methods. These Ajax event handler methods are invoked when Ajax related events are triggered like sending an Ajax request, completion of an Ajax request, and error during Ajax request processing or upon successful Ajax requests.</p>
<p>These events are triggered on each Ajax request if the global property in <i>jQuery.ajaxSetup()</i> method is set to true. The default value for this property is <i>true</i>. Please note that these global events are not fired for cross-domain requests or JSONP requests irrespective of the value of <i>global</i> property. The <i>jQuery.ajaxSetup()</i> method is used to configure default values for future Ajax requests.</p>
<ul>
<li><i><i>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></i></i></li>
</ul>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<p>The following example sends an Ajax request to a static HTML resource and shows how these events are triggered.</p>
<pre class="brush: java; title: ; notranslate">

&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      $(document).ready(function(){
	$(&quot;#ajaxBtn&quot;).click( function() {
		$(&quot;.result&quot;).load(&quot;test.html&quot;);
	});

	$(&quot;.result&quot;).ajaxStart(function(){
		console.log('ajaxStart triggered');
	});

	$(&quot;.result&quot;).ajaxSend(function(){
		console.log('ajaxSend triggered');
	});

	$(&quot;.result&quot;).ajaxError(function(){
		console.log(&quot;ajaxError triggered.&quot;);
	});

	$(&quot;.result&quot;).ajaxComplete(function(){
		console.log('ajaxComplete triggered');
	});

	$(&quot;.result&quot;).ajaxStop(function(){
		console.log('ajaxStop triggered');
	});

	$(&quot;.result&quot;).ajaxSuccess(function() {
		console.log('ajaxSuccess triggered');
	});
      });
   &lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
     &lt;div class=&quot;result&quot;&gt;&lt;/div&gt;
     &lt;input type=&quot;button&quot; id=&quot;ajaxBtn&quot; value=&quot;Send Ajax Request&quot;/&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The following screen capture shows the successful Ajax request and the sequence of events triggered. Please take note of the <i>.ajaxSuccess()</i> event triggered since the Ajax request is successful.</p>
<p><img class="size-full wp-image-5825 aligncenter" alt="jquery-ajax-events-success" src="http://www.javabeat.net/wp-content/uploads/2013/02/jquery-ajax-events-success.png" width="537" height="259" /></p>
<p>However for the failed Ajax request, the sequence is pretty much same except that the <i>.ajaxError</i> event is triggered instead of <i>.ajaxSuccess</i> as shown below.</p>
<p><img class="size-full wp-image-5824 aligncenter" alt="jquery-ajax-events-failed" src="http://www.javabeat.net/wp-content/uploads/2013/02/jquery-ajax-events-failed.png" width="538" height="222" /></p>
<h2 style="text-align: center;"><span style="color: #000080;">Summary of Ajax Event Handlers</span></h2>
<h3><strong>.ajaxStart()</strong></h3>
<p>The <i>.ajaxStart()</i> event is triggered when an Ajax request starts. This event is invoked if there are no outstanding Ajax requests in progress.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;.result&quot;).ajaxStart(function(){
console.log('ajaxStart triggered');
});
</pre>
<h3><strong>.ajaxSend()</strong></h3>
<p>The <i>.ajaxSend()</i> event is triggered just before an Ajax request is sent.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
$(&quot;.result&quot;).ajaxSend(function(){
	console.log('ajaxSend triggered');
});
</pre>
<h3><strong>.ajaxSuccess()</strong></h3>
<p>The <i>.ajaxSuccess()</i> event is triggered when an Ajax request completes successfully without any error.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;.result&quot;).ajaxSuccess(function() {
	console.log('ajaxSuccess triggered');
});
</pre>
<h3><strong>.ajaxError()</strong></h3>
<p>The <i>.ajaxError()</i> event is triggered when an Ajax request completes with error.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;.result&quot;).ajaxError(function(){
console.log(&quot;ajaxError triggered.&quot;);
});
</pre>
<p>This event is not fired when <i>.ajax()</i> or <i>.ajaxSetup()</i> are called with global property set to false.</p>
<pre class="brush: java; title: ; notranslate">
$(.result).ajaxError(function(event, request, settings) {
	console.log( &quot;Error when requesting: &quot; + settings.url);
});
</pre>
<p>If the Ajax request is failed because of any JavaScript exception, the exception object is passed<br />
to this function as a fourth parameter.</p>
<pre class="brush: java; title: ; notranslate">
$(.result).ajaxError(function(event, request, settings, exception) {
	console.log( &quot;Error when requesting: &quot; + settings.url);
});
</pre>
<h3><strong>.ajaxComplete()</strong></h3>
<p>The <i>.ajaxComplete()</i> event is fired when the Ajax request completes irrespective of the request is failed or succeeded.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;.result&quot;).ajaxComplete(function(){
console.log('ajaxComplete triggered');
});
</pre>
<h3><strong>.ajaxStop()</strong></h3>
<p>The <i>.ajaxStop()</i> event is fired when all Ajax requests have been completed and no other Ajax request is pending for processing.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;.result&quot;).ajaxStop(function(){
console.log('ajaxStop triggered');
});
</pre>
<p>The Ajax event handlers are great to get the exact status of the request. We can do pre-processing tasks like data preparation in the <i>.ajaxStart()</i> and <i>.ajaxSend()</i> methods just before sending any Ajax request. Error handling can be done in <i>.ajaxError()</i> method in case any Ajax request fails. The <i>.ajaxSuccess()</i> is useful to display acknowledgement message to the user upon successful completion of request. The events <i>.ajaxComplete()</i> and <i>.ajaxStop()</i> marks the end of Ajax request(s) so any clean up can be done in these events.</p>
<p>&nbsp;</p>
<ul>
<li><i><i>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></i></i></li>
</ul>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Ajax Introduction" href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/" rel="bookmark">jQuery Ajax Introduction</a></li>
<li><a title="Permanent Link to Refreshing DIV Content with jQuery" href="http://www.javabeat.net/2013/01/refreshing-div-content-with-jquery/" rel="bookmark">Refreshing DIV Content with jQuery</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/02/jquery-global-ajax-event-handlers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Manipulating Styles with jQuery</title>
		<link>http://www.javabeat.net/2013/02/manipulating-styles-with-jquery/</link>
		<comments>http://www.javabeat.net/2013/02/manipulating-styles-with-jquery/#comments</comments>
		<pubDate>Tue, 05 Feb 2013 00:38:36 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5807</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In the previous article we discussed about manipulating element CSS Classes using jQuery. In this article we’ll explore how to read or manipulate style properties of elements using jQuery methods. The CSS Classes defined using class attribute can be used to control the look and feel of an element. A predefined CSS definition matched with [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>In the <a href="http://www.javabeat.net/2013/02/css-class-manipulation-with-jquery/" target="_blank">previous article</a> we discussed about manipulating element CSS Classes using jQuery. In this article we’ll explore how to read or manipulate style properties of elements using jQuery methods. <span style="color: #000080;"><strong>The CSS Classes defined using <i>class</i> attribute can be used to control the look and feel of an element. A predefined CSS definition matched with <i>class</i> name is required which reflects the actual style implementation.</strong></span> However, using style properties we can straightaway manipulate the styles of the matched elements. In other words, we can read or change the elements <i>background-color</i>, <i>width</i>, <i>height</i> and many other style properties instantly. In this case, a pre-defined style definition is not required.</p>
<p>The jQuery style properties will return corresponding style value if used without any argument, at the same time used to set corresponding style value if used with an argument.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Selectors : ID selector, Class selector and Element selector" href="http://www.javabeat.net/2013/01/jquery-selectors/" rel="bookmark">jQuery Selectors : ID selector, Class selector and Element selector</a></li>
<li><a title="Permanent Link to CSS Class Manipulation with jQuery" href="http://www.javabeat.net/2013/02/css-class-manipulation-with-jquery/" rel="bookmark">CSS Class Manipulation with jQuery</a></li>
</ul>
<p>In the following example, we are reading the div <i>styleDiv</i> style properties (<i>background-color</i>, <i>width</i>, <i>height</i>) by clicking inside the <i>styleDiv</i>, and displaying them on console. At the same time we have three buttons to update the <i>background-color</i>, <i>width</i> and <i>height</i> of the div <i>styleDiv</i>. Once the properties are updated, we can see the updated properties again by clicking inside the <i>styleDiv</i>. The complete code listing is below:</p>
<ul>
<li><i>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></i></li>
</ul>
<pre class="brush: java; title: ; notranslate">
&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      $(document).ready(function() {
	$(&quot;#styleDiv&quot;).click(function() {
		console.log('styleDiv width: ' + $(&quot;#styleDiv&quot;).css('width'));
		console.log('styleDiv height: ' + $(&quot;#styleDiv&quot;).css('height'));
		console.log('styleDiv background-color: '
                    + $(&quot;#styleDiv&quot;).css('background-color'));
	});

	$(&quot;#bgColorBtn&quot;).click(function() {
	   $(&quot;#styleDiv&quot;).css({'background-color': '#c0c0c0' });
	});

	$(&quot;#widthBtn&quot;).click(function() {
	  $(&quot;#styleDiv&quot;).width(400);
	});

	$(&quot;#heightBtn&quot;).click(function() {
	  $(&quot;#styleDiv&quot;).height(150);
	});
    });
   &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;Style Properties Manipulation with jQuery&lt;/h1&gt;

    &lt;div id=&quot;styleDiv&quot; style=&quot;border:2px solid;border-radius:25px;
              text-align:center;height:100px;width:350px;&quot;&gt;
        &lt;p&gt;This is styleDiv.&lt;/p&gt;
        &lt;p&gt;Please click to see style information in the console.&lt;/p&gt;
    &lt;/div&gt;
    &lt;br/&gt;

    &lt;input type=&quot;button&quot; id=&quot;bgColorBtn&quot; value=&quot;Update Background Color&quot;/&gt;
    &lt;input type=&quot;button&quot; id=&quot;widthBtn&quot; value=&quot;Increase Width&quot;/&gt;
    &lt;input type=&quot;button&quot; id=&quot;heightBtn&quot; value=&quot;Increase Height&quot;/&gt;
   &lt;/body&gt;
&lt;/html&gt;

</pre>
<p>The following screen capture shows us on how we can read the element’s style properties.</p>
<p style="text-align: center;"><img class=" wp-image-5812 aligncenter" alt="read-style-properties" src="http://www.javabeat.net/wp-content/uploads/2013/02/read-style-properties.png" width="481" height="305" /></p>
<p>When we click on the ‘Update Background Color’ button, the <i>styleDiv</i> <i>background-color</i> property is set to html color code value <i>#c0c0c0</i>.</p>
<p style="text-align: center;"><img class=" wp-image-5811 aligncenter" alt="update-background-color" src="http://www.javabeat.net/wp-content/uploads/2013/02/update-background-color.png" width="484" height="305" /></p>
<p>When we click on the ‘Increase Width’ button, the <i>styleDiv</i> <i>width</i> property is set to new value, also we can see that the <i>styleDiv</i> has increased width. In the same way, when we click on the ‘Increase Height’ button, the <i>styleDiv</i> <i>height</i> property is set to new value, also has the increased height. The below screenshot shows the difference.</p>
<p style="text-align: center;"><img class=" wp-image-5810 aligncenter" alt="update-width-height" src="http://www.javabeat.net/wp-content/uploads/2013/02/update-width-height.png" width="479" height="328" /></p>
<p><strong>Here is the quick summary of other style properties we can work with jQuery.</strong></p>
<h3><strong>.css(propertyName)</strong></h3>
<p>Gets the style property value of an element. The below code snippet gets the <i>background-color</i> style property of the element <i>styleDiv</i>.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).css('background-color')
</pre>
<p>We can also set the style property using this method as shown below.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).css({'background-color': '#c0c0c0' });
</pre>
<h3><strong>.height(value)</strong></h3>
<p>Gets the height of an element or sets the height of an element.</p>
<p>To get the height of an element.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).css('height')
</pre>
<p>To set the height of an element.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).height(150);
</pre>
<h3><strong>.innerHeight()</strong></h3>
<p>Returns the height of the matched element including any padding (top and bottom) <b>but not border</b>. This method has no arguments.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).innerHeight()
</pre>
<h3><strong>.innerWidth()</strong></h3>
<p>Returns the width of the matched element including any padding (left and right) <b>but not border</b>. This method has no arguments.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).innerWidth()
</pre>
<h3><strong>.offset()</strong></h3>
<p>Retrieves the current position of a matched element <b>relative to the document</b>. This method returns an object containing the properties <i>left</i> and <i>top</i>.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).offset().left
$(&quot;#styleDiv&quot;).offset().top
</pre>
<h3><strong>.outerHeight(includeMargin)</strong></h3>
<p>Gets the current height of the matched element <b>including padding, border and margin</b>. If <i>includeMargin</i> is set to <i>true</i>, the margin is considered when calculating the outer height.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).outerHeight()
$(&quot;#styleDiv&quot;).outerHeight(true)
</pre>
<h3><strong>.outerWidth(includeMargin)</strong></h3>
<p>Gets the current width of the matched element <b>including padding, border and margin</b>. If <i>includeMargin</i> is set to <i>true</i>, the margin is considered when calculating the outer width.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).outerWidth()
$(&quot;#styleDiv&quot;).outerWidth(true)
</pre>
<h3><strong>.position()</strong></h3>
<p>Retrieves the current position of a matched element <b>relative to the offset of the parent element</b>. This method returns an object containing the properties <i>left</i> and <i>top</i>.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).position().left
$(&quot;#styleDiv&quot;).position().top
</pre>
<h3><strong>.scrollLeft(value)</strong></h3>
<p>Gets or sets the current horizontal scroll position of the scroll bar for the matched elements. The horizontal scroll position is the number of pixels that are hidden from view to the left of the scrollable area. If the scroll bar is at the extreme left, or if the element is not scrollable, this method returns 0.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).scrollLeft()
$(&quot;#styleDiv&quot;).scrollLeft(100)
</pre>
<h3><strong>.scrollTop(value)</strong></h3>
<p>Gets or sets the current vertical scroll position of the scroll bar for the matched elements. The vertical scroll position is the number of pixels that are hidden from view above the scrollable area. If the scroll bar is at the extreme top, or if the element is not scrollable, this method returns 0.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).scrollTop()
$(&quot;#styleDiv&quot;).scrollTop(100)
</pre>
<h3><strong>.width(value)</strong></h3>
<p>Gets the width of an element or sets the width of an element.</p>
<p>To get the width of an element.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).css('width')
</pre>
<p>To set the width of an element.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#styleDiv&quot;).width(100);
</pre>
<p><span style="color: #000080;"><strong>These jQuery methods are useful to manipulate elements style properties on the fly. The method <i>.css()</i> is useful to read, add or change style properties of any element.</strong></span> The <i>.width()</i> and <i>.height()</i> methods are used to read or set the element width or height. We can also manipulate element’s scrollable position using methods <i>.scrollLeft()</i> and <i>.scrollTop()</i> methods. The <i>.offset()</i> and <i>.position()</i> methods returns the current position of the element relative to document and parent respectively.</p>
<ul>
<li><i>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></i></li>
</ul>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Selectors : ID selector, Class selector and Element selector" href="http://www.javabeat.net/2013/01/jquery-selectors/" rel="bookmark">jQuery Selectors : ID selector, Class selector and Element selector</a></li>
<li><a title="Permanent Link to CSS Class Manipulation with jQuery" href="http://www.javabeat.net/2013/02/css-class-manipulation-with-jquery/" rel="bookmark">CSS Class Manipulation with jQuery</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/02/manipulating-styles-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS Class Manipulation with jQuery</title>
		<link>http://www.javabeat.net/2013/02/css-class-manipulation-with-jquery/</link>
		<comments>http://www.javabeat.net/2013/02/css-class-manipulation-with-jquery/#comments</comments>
		<pubDate>Sun, 03 Feb 2013 01:32:26 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5748</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Each HTML element can have a CSS class attribute which controls the look and feel of the element. The CSS class of an element corresponds to the style sheet definition. Style sheets are managed separately from HTML or any other presentation code for better maintainability. Often need arises to manipulate these class attributes to assign [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Each HTML element can have a CSS <i>class</i> attribute which controls the look and feel of the element. The CSS class of an element corresponds to the style sheet definition. Style sheets are managed separately from HTML or any other presentation code for better maintainability. Often need arises to manipulate these class attributes to assign or remove new CSS classes dynamically. jQuery caters this need by providing us methods to inspect and manipulate CSS classes assigned to the HTML elements. This article would explores the options available for manipulating the CSS properties using the jQuery.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></li>
<li><a title="Permanent Link to jQuery Selectors : ID selector, Class selector and Element selector" href="http://www.javabeat.net/2013/01/jquery-selectors/" rel="bookmark">jQuery Selectors : ID selector, Class selector and Element selector</a></li>
<li><a title="Permanent Link to Finding Duplicate Input Elements Using jQuery" href="http://www.javabeat.net/2011/03/finding-duplicate-input-elements-using-jquery/" rel="bookmark">Finding Duplicate Input Elements Using jQuery</a></li>
</ul>
<p>The following code example uses jQuery to assign new CSS class, remove an assigned CSS class, toggle adding/removing CSS class and inspects for the CSS class.</p>
<pre class="brush: java; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
&lt;style&gt;
.paragraph {font-size:20px;color:#0000cc}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
	$(&quot;#changeBtn&quot;).click(function(){
		$(&quot;p&quot;).addClass('paragraph');
	});

	$(&quot;#removeBtn&quot;).click(function(){
		$(&quot;p&quot;).removeClass('paragraph');
	});

	$(&quot;#toggleBtn&quot;).click(function(){
		$(&quot;p&quot;).toggleClass('paragraph');
	});

	$(&quot;#hasClassBtn&quot;).click(function(){
		console.log($(&quot;p&quot;).hasClass('paragraph'));
	});
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;CSS Class Manipulation with jQuery&lt;/h1&gt;
&lt;p&gt;This is a simple paragraph text.
   When 'Change' button is clicked this paragraph
   CSS class will be changed.&lt;/p&gt;

&lt;input type=&quot;button&quot; value=&quot;Change&quot; id=&quot;changeBtn&quot;/&gt;
&lt;input type=&quot;button&quot; value=&quot;Remove&quot; id=&quot;removeBtn&quot;/&gt;
&lt;input type=&quot;button&quot; value=&quot;Toggle&quot; id=&quot;toggleBtn&quot;/&gt;
&lt;input type=&quot;button&quot; value=&quot;Has Class?&quot; id=&quot;hasClassBtn&quot;/&gt;

&lt;/body&gt;
&lt;/html&gt;

</pre>
<p>Let’s discuss about the methods we used in the above example:</p>
<h2><i>.addClass</i></h2>
<p>The <i>.addClass</i> adds the specified CSS classes to the matched elements. The elements to add CSS class can be matched using selector syntax. The following code snippet adds the CSS class to all the paragraphs in the document.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).addClass('paragraph');
</pre>
<p><img class="size-full wp-image-5752 aligncenter" alt="add-class" src="http://www.javabeat.net/wp-content/uploads/2013/01/add-class.png" width="553" height="101" /></p>
<h2><i>.removeClass</i></h2>
<p>The <i>.removeClass</i> removes one or more CSS classes from the matched elements. The elements can be matched with selector syntax. The following code snippet removes the CSS class from all the paragraphs.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).removeClass('paragraph');
</pre>
<p>We can also specify multiple CSS classes to remove from matched elements as shown below:</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).removeClass('paragraph anyotherclass highlightclass');
</pre>
<p style="text-align: center;"><img class=" wp-image-5751 aligncenter" alt="remove-class" src="http://www.javabeat.net/wp-content/uploads/2013/01/remove-class.png" width="444" height="92" /></p>
<h2><i>.toggleClass</i></h2>
<p>The <i>.toggleClass</i> either adds or removes the CSS classes from the matched elements based on whether the class already present or not. In the below code example, if CSS class is not present then the CSS class is added, if it is present it will be removed.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;p&quot;).toggleClass('paragraph');
</pre>
<p style="text-align: center;"><img class=" wp-image-5750 aligncenter" alt="toggle-class" src="http://www.javabeat.net/wp-content/uploads/2013/01/toggle-class.png" width="494" height="168" /></p>
<h2><i>.hasClass</i></h2>
<p>The <i>.hasClass</i> returns boolean value on whether any matched elements have the specified class or not.</p>
<pre class="brush: java; title: ; notranslate">
console.log($(&quot;p&quot;).hasClass('paragraph'));
</pre>
<p style="text-align: left;"><img class=" wp-image-5749 aligncenter" alt="has-class" src="http://www.javabeat.net/wp-content/uploads/2013/01/has-class.png" width="504" height="326" /><br />
<span style="color: #000080;"><strong>We can manipulate the CSS classes from jQuery using <i>.addClass</i>, <i>.removeClass</i>, <i>.toggleClass</i> and <i>.hasClass</i> methods.</strong></span> These methods provide flexible ways to dynamically add or remove CSS classes to the elements to control the look and feel of the elements.</p>
<ul>
<li>Buy: <a href="http://www.flipkart.com/jquery-action-2nd/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></li>
</ul>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Selectors : ID selector, Class selector and Element selector" href="http://www.javabeat.net/2013/01/jquery-selectors/" rel="bookmark">jQuery Selectors : ID selector, Class selector and Element selector</a></li>
<li><a title="Permanent Link to Finding Duplicate Input Elements Using jQuery" href="http://www.javabeat.net/2011/03/finding-duplicate-input-elements-using-jquery/" rel="bookmark">Finding Duplicate Input Elements Using jQuery</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/02/css-class-manipulation-with-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Event Handling &#8211; Browser Events</title>
		<link>http://www.javabeat.net/2013/01/jquery-event-handling-browser-events/</link>
		<comments>http://www.javabeat.net/2013/01/jquery-event-handling-browser-events/#comments</comments>
		<pubDate>Wed, 30 Jan 2013 02:59:33 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5725</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In this article we’ll discuss about jQuery browser events. The browser events are triggered when browser is resized or scrolled or any elements have not been loaded properly by the browser. Three browser events are discussed here namely error, scroll and resize events.  Using these browser events we can do number of things like re-arranging [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>In this article we’ll discuss about jQuery browser events. The browser events are triggered when browser is resized or scrolled or any elements have not been loaded properly by the browser. Three browser events are discussed here namely <i>error</i>, <i>scroll</i> and <i>resize</i> events.  Using these browser events we can do number of things like re-arranging user interface elements when user resizes browser or loading alternative elements if primary elements failed to load or appending more content to the element when user does scrolling etc. If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to jQuery Event Handling – Form Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-form-events/" rel="bookmark">jQuery Event Handling – Form Events</a></li>
<li><a title="Permanent Link to jQuery Event Handling – Key Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-key-events/" rel="bookmark">jQuery Event Handling – Key Events</a></li>
<li><a title="Permanent Link to jQuery Event Handling – Mouse Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/" rel="bookmark">jQuery Event Handling – Mouse Events</a></li>
</ul>
<h2>Browser Events</h2>
<p>The following HTML code demonstrates the three browser events jQuery supports followed by brief description of each of these browser events.</p>
<pre class="brush: java; title: ; notranslate">

&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      $(document).ready(function(){
	     $('#myImage').error(function() {
	        console.log('myImage failed to load,
                       please assign missing image.');
	     }).attr(&quot;src&quot;, &quot;newImage.png&quot;);

	     $(&quot;#myTextarea&quot;).scroll(function() {
	        console.log(&quot;myTextarea scrolled&quot;);
	     });

	     $(window).resize(function() {
	        console.log(&quot;window resized&quot;);
	     });
          });
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;jQuery Browser Events - Demo&lt;/h1&gt;

    &lt;textarea id=&quot;myTextarea&quot; rows=&quot;2&quot; cols=&quot;10&quot;&gt;
      Please scroll this really long long text.
    &lt;/textarea&gt;

    &lt;img alt=&quot;myImageMissing&quot; id=&quot;myImage&quot; /&gt;
  &lt;/body&gt;
&lt;/html&gt;

</pre>
<h2><strong>error Event</strong></h2>
<p>The <i>error</i> event is triggered if any of the element(s) are not loaded property by the browser (like images). This event is helpful in providing alternate functionality in case any of the elements failed to load. For example, if image failed to load, we can set the alternative image as shown below.</p>
<pre class="brush: java; title: ; notranslate">
$('#myImage').error(function() {
   console.log('myImage failed to load, please assign missing image.');
}).attr(&quot;src&quot;, &quot;newImage.png&quot;);

&lt;img id=&quot;myImage&quot; alt=&quot;myImageMissing&quot; /&gt;
</pre>
<p><img class="size-full wp-image-5728 aligncenter" alt="error-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/error-event.png" width="538" height="195" /><br />
In the above code example, we’re assigning a new image for the missing image when the <i>error</i> event is triggered.</p>
<h2><strong>scroll Event</strong></h2>
<p>The <i>scroll</i> event is triggered when user scrolls the element. This event can be applied to <i>window</i> objects or scrollable frames or any element with CSS property <i>overflow</i> set to <i>scroll</i> or <i>auto</i>.</p>
<pre class="brush: java; title: ; notranslate">

$(&quot;#myTextarea&quot;).scroll(function() {
   console.log(&quot;myTextarea scrolled&quot;);
});

&lt;textarea cols=&quot;10&quot; rows=&quot;2&quot;&gt;
    Please scroll this really long long text.
&lt;/textarea&gt;
</pre>
<p><img class="size-full wp-image-5727 aligncenter" alt="scroll-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/scroll-event.png" width="444" height="276" /></p>
<p>In the above screen capture, the <i>scroll</i> event is triggered when user scrolls the <i>textarea</i>.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h2><strong>resize Event</strong></h2>
<p>The <i>resize</i> event is triggered when width or height of the browser window is changed by resizing.</p>
<pre class="brush: java; title: ; notranslate">
$(window).resize(function() {
   console.log(&quot;window resized&quot;);
});
</pre>
<p><img class="size-full wp-image-5726 aligncenter" alt="resize-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/resize-event.png" width="541" height="197" /></p>
<p>The <i>resize</i> event is triggered when user minimizes or maximizes or resizes the browser window.</p>
<p>The jQuery browser events useful in scenarios we need to capture the point where user resized the browser window. We may want to do UI re-structuring when browser window is resized, or want to hide some of the elements when the screen is resized to minimum width and height. We can use <i>resize </i>event to achieve this type of functionality.</p>
<p>In the same way, <i>scroll</i> event is useful to show or hide large amounts of data in HTML elements. The <i>scroll</i> event is triggered when user clicks on the horizontal or vertical scroll bars of element to scroll, or when user uses mouse scroll wheel to  scroll the area.</p>
<p>The <i>error </i>event is useful to provide fallback logic if browser failed to load any elements like images or videos.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to jQuery Event Handling – Form Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-form-events/" rel="bookmark">jQuery Event Handling – Form Events</a></li>
<li><a title="Permanent Link to jQuery Event Handling – Key Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-key-events/" rel="bookmark">jQuery Event Handling – Key Events</a></li>
<li><a title="Permanent Link to jQuery Event Handling – Mouse Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/" rel="bookmark">jQuery Event Handling – Mouse Events</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/01/jquery-event-handling-browser-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Event Handling – Form Events</title>
		<link>http://www.javabeat.net/2013/01/jquery-event-handling-form-events/</link>
		<comments>http://www.javabeat.net/2013/01/jquery-event-handling-form-events/#comments</comments>
		<pubDate>Sat, 26 Jan 2013 15:43:12 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5622</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>We discussed about mouse events, keyboard events in previous articles. This article discusses about form events jQuery supports. jQuery has five form events namely blur(), change(), focus(), select() and submit(). These events are triggered when we interact with HTML form elements like moving away from the element or when the element loses its focus, changing [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>We discussed about <a href="http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/" target="_blank">mouse events</a>, <a href="http://www.javabeat.net/2013/01/jquery-event-handling-key-events/" target="_blank">keyboard events</a> in previous articles. This article discusses about form events jQuery supports. jQuery has five form events namely blur(), change(), focus(), select() and submit(). These events are triggered when we interact with HTML form elements like moving away from the element or when the element loses its focus, changing element text or value, when element&#8217;s inside text is selected, when the element gets the focus, and submitting a form respectively. If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to jQuery Event Handling – Key Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-key-events/" rel="bookmark">jQuery Event Handling – Key Events</a></li>
<li><a title="Permanent Link to jQuery Event Handling – Mouse Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/" rel="bookmark">jQuery Event Handling – Mouse Events</a></li>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
</ul>
<p>The following HTML code creates a form with input text box and a submit button to demonstrate how form events are triggered. These jQuery form events are bind to the text box and form.</p>
<pre class="brush: java; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
  &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      $(document).ready(function(){
	$(&quot;#name&quot;).blur(function() {
		console.log(&quot;blur() event is triggered, name textbox lost focus.&quot;);
	});

	$(&quot;#name&quot;).change(function() {
		console.log(&quot;change() event is triggered, name textbox is changed.&quot;);
	});

	$(&quot;#name&quot;).focus(function() {
		console.log(&quot;focus() event is triggered, name textbox gets focus.&quot;);
	});

	$(&quot;#name&quot;).select(function() {
		console.log(&quot;select() event is triggered, name textbox selected.&quot;);
	});

	$(&quot;#registerForm&quot;).submit(function() {
	  console.log(&quot;submit() event is triggered,
                form registerForm is about to be submitted.&quot;);
		return false;
	});
    });
   &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;h1&gt;jQuery Form Events - Demo&lt;/h1&gt;
   &lt;form id=&quot;registerForm&quot;
         name=&quot;registerForm&quot;
         action=&quot;webapp/register.php&quot; method=&quot;POST&quot;&gt;
  Name: &lt;input type=&quot;text&quot; id=&quot;name&quot;/&gt;&lt;br/&gt;&lt;br/&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
   &lt;/form&gt;
  &lt;/body&gt;
&lt;/html&gt;

</pre>
<h3><strong>blur</strong></h3>
<p>The blur event is triggered when an element loses its focus. The below screen capture shows us that the blur event is triggered when text input loses its focus and submit button gets focus.</p>
<p><img class="size-full wp-image-5627 aligncenter" alt="blur-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/blur-event.png" width="538" height="264" /></p>
<h3><strong>change</strong></h3>
<p>The change event is triggered when element values is changed. The below screen shows us that change event is triggered when element value has been changed.</p>
<p><img class="size-full wp-image-5626 aligncenter" alt="change-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/change-event.png" width="547" height="258" /></p>
<p class="MsoNormal">Note that in the case of text input and any other input elements the change event is triggered when element value is changed and element loses focus. For select boxes, checkboxes and radio buttons the change event is triggered immediately upon user selection.</p>
<h3><strong>focus</strong></h3>
<p class="MsoNormal">The focus event is triggered when element gets focus. The below screen describes the focus event being triggered on text input.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><img class="size-full wp-image-5625 aligncenter" alt="focus-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/focus-event.png" width="535" height="259" /></p>
<h3><strong>select</strong></h3>
<p>The select event is triggered when element inside text is selected. The below screen demonstrates the select event being triggered as soon as user selected the text. This event is only applicable to input type text and textarea.</p>
<p><img class="size-full wp-image-5624 aligncenter" alt="select-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/select-event.png" width="535" height="233" /></p>
<h3><strong>submit</strong></h3>
<p>The submit event is triggered when trying to submit a form. This event can only be attached to a form.</p>
<p><img class="size-full wp-image-5623 aligncenter" alt="submit-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/submit-event.png" width="537" height="238" /></p>
<p>The jQuery form events are useful in various ways. The blur and change events can be used to perform data validations and to inform user if invalid data is entered. The focus event can be used to refresh the data in the HTML element as soon as user arrives at the element. The select event can be used to provide functionality like copy or cut when user selects text inside the element. Finally, the submit event can be used to perform any validation checks or to execute any pre-processing tasks before the form submission.</p>
<p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to jQuery Event Handling – Key Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-key-events/" rel="bookmark">jQuery Event Handling – Key Events</a></li>
<li><a title="Permanent Link to jQuery Event Handling – Mouse Events" href="http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/" rel="bookmark">jQuery Event Handling – Mouse Events</a></li>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
</ul>
<p>If you have any questions, please post it in the comments section. If you are interested in receiving the future articles on jQuery and Java topics, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/01/jquery-event-handling-form-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Event Handling – Key Events</title>
		<link>http://www.javabeat.net/2013/01/jquery-event-handling-key-events/</link>
		<comments>http://www.javabeat.net/2013/01/jquery-event-handling-key-events/#comments</comments>
		<pubDate>Tue, 22 Jan 2013 13:50:07 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5589</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In addition to mouse events, jQuery also responds to key board events when user presses any key on the keyboard, presses key down, releases key up, input element receives focus, or input element looses focus. These events are triggered when user interacts with the keyboard. In general, these key events are bound to the HTML [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>In addition to <a href="http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/">mouse events</a>, <strong>jQuery</strong> also responds to key board events when user presses any key on the keyboard, presses key down, releases key up, input element receives focus, or input element looses focus. These events are triggered when user interacts with the keyboard. In general, these key events are bound to the HTML elements, however, the key events can be bound to any element. The event is triggered only when the element gets the focus.</p>
<p>The following HTML code demonstrates the key events supported by the <strong>jQuery</strong>.</p>
<p><strong>also read:</strong></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Selectors : ID selector, Class selector and Element selector" href="http://www.javabeat.net/2013/01/jquery-selectors/" rel="bookmark">jQuery Selectors : ID selector, Class selector and Element selector</a></li>
</ul>
<blockquote><p><strong>If you are looking for a good book on jQuery, please buy <a href="http://www.flipkart.com/jquery-action-9350040980/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></strong></p></blockquote>
<pre class="brush: java; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
 &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
	$(document).keypress(function(eventObject){
	    console.log('key pressed &amp; key code is: ' + eventObject.which);
	});

	$(document).keyup(function(eventObject){
	    console.log('key up &amp; key code is: ' + eventObject.which);
	});

	$(document).keydown(function(eventObject){
	    console.log('key down &amp; key code is: ' + eventObject.which);
	});

	$(&quot;#focusInput&quot;).focusin(function(){
	    console.log('focusInput got the focus');
	});

	$(&quot;#focusInput&quot;).focusout(function(){
	    console.log('focusInput lost focus');
	});

});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;input type=&quot;text&quot; id=&quot;focusInput&quot;/&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><img class="size-full wp-image-5611 aligncenter" alt="key_events-demo" src="http://www.javabeat.net/wp-content/uploads/2013/01/key_events-demo.png" width="600" height="374" /></p>
<p>Notice how the key code is displayed whenever we press any key on the keyboard. We are accessing property of eventObject, ‘which’ to get the key code of the key pressed. Similarly, we have an input textbox which is configured with focusin and focusout events. The focusin is triggered when we put cursor into that textbox. The focusout is triggered when we take away focus of the textbox by clicking some other widget or outside the textbox.</p>
<p>The following is the quick summary of the <strong>jQuery</strong> key events.</p>
<h1 style="text-align: center;"><span style="color: #000080;">jQuery Key Events – Quick Summary</span></h1>
<h2>keyPress</h2>
<p>The ‘keyPress’ event is triggered when any key is pressed on the keyboard. We can get the key code of the key pressed from the ‘which’ property of the event object as shown below:</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
$(document).keypress(function(eventObject){
    console.log('key pressed &amp; key code is: ' + eventObject.which);
});
</pre>
<h2>keyUp</h2>
<p>The ‘keyUp’ event is triggered when user presses any key and releases the key on the keyboard. The ‘which’ property of the event object gives us the key code of the released key.</p>
<pre class="brush: java; title: ; notranslate">
$(document).keyup(function(eventObject){
    console.log('key up &amp; key code is: ' + eventObject.which);
});
</pre>
<h2>keyDown</h2>
<p>The ‘keyDown’ event is triggered when user presses any key on the keyboard. The ‘which’ property of the event object gives us the key code of the key pressed.</p>
<pre class="brush: java; title: ; notranslate">
$(document).keydown(function(eventObject){
    console.log('key down &amp; key code is: ' + eventObject.which);
});
</pre>
<h2>focusIn</h2>
<p>The ‘focusIn’ event is triggered when any element gets focus.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#focusInput&quot;).focusin(function(){
    console.log('focusInput got the focus');
});
</pre>
<h2>focusOut</h2>
<p>The ‘focusOut’ event is triggered when any element loses its focus.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#focusInput&quot;).focusout(function(){
    console.log('focusInput lost focus');
});
</pre>
<p><strong>jQuery</strong> key events are great way to have control over which key user presses or releases, which <strong>HTML</strong> widget gets focus or loses focus.The &#8216;focusin&#8217; event can be used to execute the business logic via <strong>AJAX</strong> call to load and render the data in the widget. The &#8216;focusout&#8217; event can be used to perform validations against the widget input and alert the user about any invalid input when user moves out of the widget.</p>
<p><strong>also read:</strong></p>
<ul>
<li><a title="Permanent Link to Introduction to jQuery" href="http://www.javabeat.net/2012/12/introduction-to-jquery/" rel="bookmark">Introduction to jQuery</a></li>
<li><a title="Permanent Link to jQuery Selectors : ID selector, Class selector and Element selector" href="http://www.javabeat.net/2013/01/jquery-selectors/" rel="bookmark">jQuery Selectors : ID selector, Class selector and Element selector</a></li>
</ul>
<blockquote><p><strong>If you are looking for a good book on jQuery, please buy <a href="http://www.flipkart.com/jquery-action-9350040980/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></strong></p></blockquote>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/01/jquery-event-handling-key-events/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Event Handling – Mouse Events</title>
		<link>http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/</link>
		<comments>http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/#comments</comments>
		<pubDate>Sat, 19 Jan 2013 11:02:11 +0000</pubDate>
		<dc:creator>Ganesh Prakhya</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5533</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>jQuery provides sophisticated event handling mechanism. jQuery responds to clicks, double clicks, mouse up and mouse down events, page load, key events like key up and down and other relevant events. We can have custom functions which are invoked and executed when any of the event triggers. The following simple HTML file creates a DIV [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><strong>jQuery</strong> provides sophisticated event handling mechanism. <strong>jQuery</strong> responds to clicks, double clicks, mouse up and mouse down events, page load, key events like key up and down and other relevant events. We can have custom functions which are invoked and executed when any of the event triggers.</p>
<p>The following simple HTML file creates a DIV areaDiv and configures click, dblclick, mouseenter and mouseleave events to demonstrate how the event handling works in <strong>jQuery</strong>.</p>
<p><strong>also read:</strong></p>
<ul>
<li><a href="http://www.javabeat.net/2012/12/introduction-to-jquery/">Introduction to jQuery</a></li>
<li><a href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/">What is jQuery Ajax?</a></li>
</ul>
<blockquote><p><strong>If you are looking for a good book on jQuery, please buy <a href="http://www.flipkart.com/jquery-action-9350040980/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></strong></p></blockquote>
<pre class="brush: java; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.8.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){
	$(&quot;#areaDiv&quot;).click(function(){
		console.log('Click inside areaDiv');
	});

	$(&quot;#areaDiv&quot;).dblclick(function(){
		console.log('Double click inside areaDiv');
	});

	$(&quot;#areaDiv&quot;).mouseenter(function(){
		console.log('Mouse entered areaDiv');
	});

	$(&quot;#areaDiv&quot;).mouseleave(function(){
		console.log('Mouse exit from areaDiv');
	});
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;areaDiv&quot; style=&quot;border:2px solid;border-radius:25px;
    text-align:center;height:100px;&quot;&gt;
This is area div.
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The following screen captures shows us that every time we enter into the areaDiv, the mouseenter event is triggered and displays a message to the console.<br />
<img class="size-full wp-image-5575 aligncenter" alt="mouse-exut-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/mouse-enter-event.png" width="434" height="185" /></p>
<p>In the same way, a message is displayed to the console when we move out of the areaDiv.<br />
<img class="size-full wp-image-5575 aligncenter" alt="mouse-exut-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/mouse-exut-event.png" width="484" height="200" /></p>
<p>Subsequently, click and dblclick events also triggered when we click and double click inside the areaDiv respectively.<br />
<img class="size-full wp-image-5575 aligncenter" alt="mouse-exut-event" src="http://www.javabeat.net/wp-content/uploads/2013/01/mouse-clicks.png" width="440" height="290" /></p>
<p><span style="color: #000080;"><strong><em>NOTE: Please enable Firebug in your Firefox browser and then click on Console tab in the Firebug panel to see the log messages displayed.</em></strong></span></p>
<p>The below section quickly summarizes the mouse events jQuery supports.</p>
<h2>jQuery Mouse Events – Quick Reference</h2>
<p>jQuery mouse events are triggered when user interacts with mouse. The following are the mouse events jQuery supports:</p>
<h3><strong>jQuery Event &#8211; click</strong></h3>
<p>Triggered when user clicks on the element.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
$(&quot;#btn&quot;).click(function(){
    alert('Button Clicked');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>dblclick</strong></h3>
<p>Triggered when user double clicks on the element.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#dblClickDiv&quot;).dblclick(function(){
    alert('Double Clicked');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>mousedown</strong></h3>
<p>Similar to click. Triggered when mouse point is over an element and mouse button is pressed.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#mouseDownDiv&quot;).mousedown(function(){
    alert('Mousedown');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>mouseenter</strong></h3>
<p>Triggered when mouse pointer enters the element.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#mouseEnterDiv&quot;).mouseenter(function(){
    alert('Mouse Enter');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>mouseleave</strong></h3>
<pre class="brush: java; title: ; notranslate">
Triggered when mouse pointer leaves the element.
$(&quot;#mouseLeaveDiv&quot;).mouseleave(function(){
    alert('Mouse Leave');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>mousemove</strong></h3>
<p>Triggered when mouse pointer moves inside the element.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#mouseMoveDiv&quot;).mousemove(function(){
    alert('Mouse Moved');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>mouseout</strong></h3>
<p>Similar to mouseleave event. Triggered when mouse pointer leaves an element. This event is also triggered when mouse pointer leaves any of child elements.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#mouseOutDiv&quot;).mouseout(function(){
    alert('Mouse Out');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>mouseover</strong></h3>
<p>Triggered when mouse pointer enters an element.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#mouseOverDiv&quot;).mouseover(function(){
    alert('Mouse Over');
});
</pre>
<h3><strong><strong>jQuery Event &#8211; </strong>mouseup</strong></h3>
<p>Triggered when mouse pointer is over an element and mouse button is released.</p>
<pre class="brush: java; title: ; notranslate">
$(&quot;#mouseUpDiv&quot;).mouseup(function(){
    alert('Mouse Up');
});
</pre>
<p>In addition to mouse events <strong>jQuery</strong> also supports key events triggered when user interacts with keyboard. We’ll discuss about <strong>jQuery</strong> key events in another article.</p>
<p><strong>also read:</strong></p>
<ul>
<li><a href="http://www.javabeat.net/2012/12/introduction-to-jquery/">Introduction to jQuery</a></li>
<li><a href="http://www.javabeat.net/2013/01/jquery-ajax-introduction/">What is jQuery Ajax?</a></li>
</ul>
<blockquote><p><strong>If you are looking for a good book on jQuery, please buy <a href="http://www.flipkart.com/jquery-action-9350040980/p/itmdynbykehbwgh6?pid=9789350040980&amp;affid=suthukrish" target="_blank">jQuery in Action</a></strong></p></blockquote>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/01/jquery-event-handling-mouse-events/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
